I am working on a site currently (first one solo) and went to go make an index page. I have been attempting to follow django best practices as I go, so naturally I go search for this but couldn't a real standard in regards to this.
I have seen folks creating apps to serve this purpose named various things (main, home, misc) and have seen a views.py in the root of the project. I am really just looking for what the majority out there do for this.
The index page is not static, since I want to detect if the user is logged in and such.
Thanks.
If all of your dynamic content is handled in the template (for example, if it's just simple checking if a user is present on the request), then I recommend using a generic view, specificially the direct to template view:
urlpatterns = patterns('django.views.generic.simple',
(r'^$', 'direct_to_template', {'template': 'index.html'}),
)
If you want to add a few more bits of information to the template context, there is another argument, extra_context
, that you can pass to the generic view to include it:
extra_context = {
'foo': 'bar',
# etc
}
urlpatterns = patterns('django.views.generic.simple',
(r'^$', 'direct_to_template', {'template': 'index.html', 'extra_context': extra_context }),
)
I tend to create a views.py
in the root of the project where I keep the index
view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With