It can get unwieldy to store all of your templates in a single directory. You might like to store templates in subdirectories of your template directory, and that's fine.
In fact, I recommend doing so; some more advanced Django features (such as the generic views system, which we cover in Chapter 10, Generic Views) expect this template layout as a default convention.
Storing templates in subdirectories of your template directory is easy. In your calls to get_template()
, just include the subdirectory name and a slash before the template name, like so:
t = get_template('dateapp/current_datetime.html')
Because render()
is a small wrapper around get_template()
, you can do the same thing with the second argument to render()
, like this:
return render(request, 'dateapp/current_datetime.html', {'current_date': now})
There's no limit to the depth of your subdirectory tree. feel free to use as many subdirectories as you like.