Django cannot find a template

I know that many people asked this question, but despite hard-coding the path to my template directory, I cannot get Django to find my template.

Here is the settings.py parameter

TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', #django.template.loaders.eggs.Loader', ) TEMPLATE_DIRS = ( "/Users/full/path/to/marketing_site/templates", ) 

This is the views.py file:

 def static (request, feature_page): # this will get the appropriate feature page template. template = loader.get_template('features/pricing.html') c = RequestContext(request,{ }) return HttpResponse(template.render(c)) 

Inside the main folder is the templates folder and the application folder. I use to place applications in the same folder as settings.py, but django 1.4 seems to have changed the default file structure.

My mistake:

 TemplateDoesNotExist at /features/pricing Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: /Library/Python/2.7/site-packages/django/contrib/auth/templates/feature_pricing.html (File does not exist) 

Update:
My logs for the webpage list TEMPLATE_DIRS as ().

If I put the print statement on the settings.py page for TEMPLATE_DIRS, I get a print of TEMPLATE_DIRS accordingly ... so that TEMPLATE_DIRS is not used (what it looks like)

+4
source share
4 answers

I added an extra TEMPLATE_DIR to settings.py

: (

+7
source

better set up relative paths for your path variables. You can configure it like this:

 import os PATH_PROJECT = os.path.realpath(os.path.dirname(__file__)) ... ... TEMPLATE_DIRS = ( PATH_PROJECT + '/templates/' ) 

Assuming you are using windows, you can try:

 TEMPLATE_DIRS = ( "C:/Users/full/path/to/marketing_site/templates", ) 
+4
source

I am sure that /Users/full/path/to/marketing_site/templates does not contain the features directory, or /Users/full/path/to/marketing_site/templates/features does not contain the pricing.html file.

Based on your comment, it looks like you are calling loader.get_template('feature_pricing.‌​html') instead of using 'feature/pricing.html' .

EDIT: I haven't noticed this before:

Inside the main folder is the templates folder and the application folder. I use to place applications in the same folder as settings.py, but django 1.4 seems to have changed the default file structure.

This may cause a problem. Modify the directory structure to comply with the Django 1.4 conventions. You can simply recreate the project, copy the appropriate settings to the new settings.py creation and copy all the files.

+1
source

Try adding project paths to django.wsgi

 import os import sys paths = ('path/to/project/', 'path/to/more /included/directories/', ) for path in paths: if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 
+1
source

All Articles