Template subdirectories

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 10Generic 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 ...

Get Mastering Django: Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.