Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24809 closed Bug (invalid)

Won't load templates from apps directory without a model

Reported by: Camilo Ernesto Forero Owned by: nobody
Component: Template system Version: 1.8
Severity: Normal Keywords: app loader
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When creating a new app, the templates loader won't look at the <appname>/templates directory if there are no models of it migrated to the database, throwing a TemplateDoesNotExist exception and showing in the postmortem that it only looked for them in the 'auth' and 'admin' application template directories. The new app had already been added to the 'INSTALLED_APPS' section of the settings.py file. Doing a makemigrations and a migrate did nothing

This was fixed after I created a dummy class in <appname>/models.py, and did a makemigrations->migrate. So my guess is that the template loader relies somehow in the database, and if there is no reference to an app on it then it won't look at it's templates directories despite it being on the INSTALLED_APPS tuple. So I don't know if that's intended behaviour or not, but here I call it to your attention.

Change History (4)

comment:1 by Baptiste Mispelon, 9 years ago

Hi,

I just tried to reproduce your issue using the following app structure:

bug24809/
├── __init__.py
└── templates
    └── foo.html

After I added the app to settings.INSTALLED_APPS, I tried django.template.loader.get_template('foo.html') and it did return a template object (no TemplateDoesNotExist exception).

Do you have more information on how to reproduce your issue?
Thanks.

comment:2 by Aymeric Augustin, 9 years ago

Resolution: needsinfo
Status: newclosed

Given the amount of work that was put in Django 1.7 to make sure models.py is optional, I'm pretty sure this isn't a behavior you'll see with vanilla Django. The template layer is also decoupled from the model layer, so there's no reason they would interact like this. Something else must be going on in your project.

comment:3 by Camilo Ernesto Forero, 9 years ago

I just tried to reproduce the issue but this time it worked as normal, with no models. The error must have been somewhere else. Thank you

comment:4 by Tim Graham, 9 years ago

Resolution: needsinfoinvalid
Note: See TracTickets for help on using tickets.
Back to Top