Yugal Jindle
Yugal Jindle

Reputation: 45696

Django : How to structure template folder considering template tag includes?

I have my template folder with all html templates lieing together in the template folder with no directory structure as such.

I decided to arrange them on per app basis, but:

  • A template with template-tags belong to different apps.

Eg: Login page(Login app) includes a banner that belongs to UserActivity [User activity app]. So, if I include the login template in login folder in templates, then it will be including stuff across other app's template folder.

How should I structure so that all that referred stays in 1 place organized ?

Feel free to ask for more info.. :)

Upvotes: 2

Views: 4696

Answers (1)

arie
arie

Reputation: 18982

Organizing your templates in subdirectories is definitely they way to go, but I am not sure if you can really reach the level of separation you are looking for. If your apps depend on each other you'll always have includes and tags from other apps. So i'd put the templates to the app they belong to.

But maybe the docs about template loaders can help you clarify your structure.

For example the app_directories.Loader

Loads templates from Django apps on the filesystem. For each app in INSTALLED_APPS, the loader looks for a templates subdirectory. If the directory exists, Django looks for templates in there.

This means you can store templates with your individual apps. This also makes it easy to distribute Django apps with default templates.

So you could put app-specific templates in in your app directories and keep your general templates (base.html, etc.) in the top level template dir of your project.

Upvotes: 6

Related Questions