i want to set a main page or an index page for my app. i tried adding MAIN_PAGE in settings.py and then creating a main_page view returning a main_page object, but it doesn't work Also, i tries to add in the urls.py a declaration like
(r'^$', index),
where indexshould be the name of the index.html file on the root (but it obviously does not work)
What is the best way to set a main page in a Django website?
thanks!
In case someone searching for an updated version of the answer..
and in your
views.py
If you want to refer to a static page (not have it go through any dynamic processing), you can use the
direct_to_template
view function fromdjango.views.generic.simple
. In your URL conf:(Assuming
index.html
is at the root of one of your template directories.)The new preferred way of doing this would be to use the
TemplateView
class. See this SO answer if you would like to move fromdirect_to_template
.In your main
urls.py
file:Note, I choose to put any static pages linke
index.html
in its own directorystatic_pages/
within thetemplates/
directory.You could use the generic
direct_to_template
view function: