2015-05-15 6 views
8

Das macht mich verrückt. Ich habe etwas seltsam gemacht und es scheint, dass meine TEMPLATE_DIRS Einträge ignoriert werden. Ich habe nur eine settings.py Datei im Projektverzeichnis befindet, und es enthält:Django 1.8 TEMPLATE_DIRS wird ignoriert

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'), 
    os.path.join(BASE_DIR, 'web_app/views/'), 
) 

I Projekt-Level-Vorlagen in den/templates Ordner bin setzen, und dann Ordner für verschiedene Ansichtskategorien haben in meiner App-Ordner (z. B. Authentifizierungsansichten, Kontoansichten usw.).

Zum Beispiel meine Hauptindex Seitenansicht ist in web_app/Ansichten/main/views_main.py und sieht aus wie

from web_app.views.view_classes import AuthenticatedView, AppView 


class Index(AppView): 
    template_name = "main/templates/index.html" 

wo ein AppView nur eine Erweiterung von TemplateView ist. Hier ist mein Problem: wenn ich versuche, um die Seite zu besuchen, erhalte ich eine TemplateDoesNotExist Ausnahme und der Teil, der mich wirklich verwirrend ist die Template-Loader Postmortem:

Template-loader postmortem 

Django tried loading these templates, in this order: 
Using loader django.template.loaders.filesystem.Loader: 
Using loader django.template.loaders.app_directories.Loader: 
C:\Python34\lib\site-packages\django\contrib\admin\templates\main\templates\index.html (File does not exist) 
C:\Python34\lib\site-packages\django\contrib\auth\templates\main\templates\index.html (File does not exist) 

Warum in der Welt sind die ‚Vorlagen‘ und ‚web_app/views 'Verzeichnisse werden nicht durchsucht? Ich habe Einstellungen über den Debugger und einen Haltepunkt in views_main.py überprüft und es sieht so aus, als wären sie drin. Hat jemand ein ähnliches Problem gehabt? Vielen Dank.

Antwort

24

Welche Version von Django verwenden Sie? TEMPLATE_DIRS ist veraltet, da 1,8

seit Version Veraltet 1,8: die DIRS Option einer Backend DjangoTemplates Set statt.

https://docs.djangoproject.com/en/1.8/ref/settings/#template-dirs

diese Anstatt also versuchen:

TEMPLATES = [ 
    { 
    'BACKEND': 'django.template.backends.django.DjangoTemplates', 
    'DIRS': [ 
     # insert your TEMPLATE_DIRS here 
    ], 
    'APP_DIRS': True, 
    'OPTIONS': { 
     'context_processors': [ 
      # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this 
      # list if you haven't customized them: 
      'django.contrib.auth.context_processors.auth', 
      'django.template.context_processors.debug', 
      'django.template.context_processors.i18n', 
      'django.template.context_processors.media', 
      'django.template.context_processors.static', 
      'django.template.context_processors.tz', 
      'django.contrib.messages.context_processors.messages', 
     ], 
    }, 

    }, 
] 

Hier ein Link zu einem Upgrade-Leitfaden ist: https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/

+0

Yep. Das war's. Nun, das war eine solide Nutzung von zwei Stunden. Vielen Dank! – Gadzooks34