[Django]-Django index page best/most common practice

19πŸ‘

βœ…

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 }),
)
πŸ‘€TM.

3πŸ‘

I tend to create a views.py in the root of the project where I keep the index view.

πŸ‘€ayaz

Leave a comment