Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't put templates at app root level #64

Closed
chosak opened this issue Aug 17, 2017 · 1 comment
Closed

Don't put templates at app root level #64

chosak opened this issue Aug 17, 2017 · 1 comment

Comments

@chosak
Copy link
Member

chosak commented Aug 17, 2017

The templates for this app are located in the root ccdb5_ui/templates level and thus referred to with no subdirectories when rendering, e.g. template_name = 'standalone-base.html'.

This works as long as all template names are guaranteed to be unique across all apps in a Django project, but could cause conflicts if, say, another app also has a standalone_base.html in its root templates directory. Prefixing all template names with ccdb- might work but has to be done consistently.

The Django convention seems to be to place templates under subdirectories named for the app, e.g. ccdb5-ui/templates/ccdb5-ui/main.html. At first this might feel duplicative but it makes the view code clearer, especially if these templates are ever referred to from another project, e.g. 'template_name = 'ccdb5-ui/main.hml.

From the Django tutorial:

Now we might be able to get away with putting our templates directly in polls/templates (rather than creating another polls subdirectory), but it would actually be a bad idea. Django will choose the first template it finds whose name matches, and if you had a template with the same name in a different application, Django would be unable to distinguish between them. We need to be able to point Django at the right one, and the easiest way to ensure this is by namespacing them. That is, by putting those templates inside another directory named for the application itself.

Current behavior

Templates for this app live under ccdb5-ui/templates.

Expected behavior

Templates for this app live under ccdb5-ui/templates/ccdb5-ui.

@chosak
Copy link
Member Author

chosak commented Aug 25, 2017

Thank you @sephcoster!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant