虚拟项目的目录结构
/dummy
/dummy
urls.py
views.py
setting.py
_init_
wsgi.py
/template
home.html
settings.py
TEMPLATE_DIRS = (
"D:/Data/Codes/Django_Code/dummy/template"
)
views.py
from django.shortcuts import render_to_response
from django.template import RequestContext
def home_view(request):
render_to_response(request, 'home.html')
urls.py
from django.conf.urls import patterns, include, url
from dummy.views import home_view
urlpatterns = patterns('',
url(r'^home/$', home_view),
)
在TemplateDoesNotExist上摸不着头虽然在TEMPLATE_DIRS下的setting.py中指定了模板目录
错误跟踪 模板加载器postmortem
Django尝试按以下顺序加载这些模板: 使用loader django.template.loaders.filesystem.Loader: d:\ DATA \代码\ Django_Code \哑\模板\ POST:, COOKIES:{' csrftoken':' CNnHomGRMMJmik75Pi2rclMVdPjO36t9'}, META:{' ALLUSERSPROFILE':' C:\ ProgramData', ' APPDATA':' C:\ Users \ nitin \ AppData \ Roaming', ' CLASSPATH':'。; D:\ data \ Codes; C:\ Users \ nitin \ Downloads \ javapostmark \ apache-mime4j-0.6.jar; C:\ Users \ nitin \ Downloads \ javapostmark \公地编解码器-1.3.jar; C:\ Users \用户尼丁\下载\ javapostmark \共享记录-1.1.1.jar; C:\ Users \用户尼丁\下载\ javapostmark \ GSON-1.4.jar; C: \ Users \用户尼丁\下载\ javapostmark \ HttpClient的-4.0.1.jar; C:\ Users \用户尼丁\下载\ javapostmark \的HttpCore-4.0.1.jar; C:\ Users \用户尼丁\下载\ javapostmark \ httpmime-4.0 .1.jar; C:\ Users \用户尼丁\下载\ javapostmark \乔达 - 时间 - 1.6.jar;&#39 ;, ' COMMONPROGRAMFILES':' C:\ Program Files \ Common Files', ' COMMONPROGRAMFILES(X86)':' C:\ Program Files(x86)\ Common Files', ' COMMONPROGRAMW6432':' C:\ Program Files \ Common Files', ' COMPUTERNAME':' NITIN-PC', ' COMSPEC':' C:\ Windows \ system32 \ cmd.exe', ' CONTENT_LENGTH':'', ' CONTENT_TYPE':' text \ plain', ' CSRF_COOKIE':' CNnHomGRMMJmik75Pi2rclMVdPjO36t9', ' DJANGO_SETTINGS_MODULE':' dummy.settings', ' FP_NO_HOST_CHECK':'否', ' GATEWAY_INTERFACE':' CGI \ 1.1', ' HOMEDRIVE':' C:', ' HOMEPATH' \#39; \ Users \ nitin', ' HTTP_ACCEPT':' text \ html,application \ xhtml + xml,application \ xml; q = 0.9,* \ *; q = 0.8', ' HTTP_ACCEPT_CHARSET':' ISO-8859-1,utf-8; q = 0.7,*; q = 0.3', ' HTTP_ACCEPT_ENCODING':' gzip,deflate,sdch', ' HTTP_ACCEPT_LANGUAGE':' en-US,en; q = 0.8', ' HTTP_CACHE_CONTROL':' max-age = 0', ' HTTP_CONNECTION':' keep-alive', ' HTTP_COOKIE':' csrftoken = CNnHomGRMMJmik75Pi2rclMVdPjO36t9', ' HTTP_HOST':' 127.0.0.1:8000', ' HTTP_USER_AGENT':' Mozilla \ 5.0(Windows NT 6.1; WOW64)AppleWebKit \ 537.4(KHTML,如Gecko)Chrome \ 22.0.1229.94 Safari \ 537.4', ' JAVA_HOME':' C:\ Program Files(x86)\ Java \ jdk1.7.0_05;', ' LOCALAPPDATA':' C:\ Users \ nitin \ AppData \ Local', ' LOGONSERVER':' \ NITIN-PC', ' NUMBER_OF_PROCESSORS':' 2', ' OS':' Windows_NT', ' PATH':' C:\ Program Files(x86)\ Java \ jdk1.7.0_05 \ bin; C:\ Python27; C:\ Python27 \; C:\ Python27 \ Scripts&#39 ;, ' PATHEXT':' .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS; .JSE; .WSF; .WSH; .MSC', ' PATH_INFO':你' \ home \', ' PROCESSOR_ARCHITECTURE':' AMD64', ' PROCESSOR_IDENTIFIER':' Intel64 Family 6 Model 23 Stepping 10,GenuineIntel', ' PROCESSOR_LEVEL':' 6', ' PROCESSOR_REVISION':' 170a', ' PROGRAMDATA':' C:\ ProgramData', ' PROGRAMFILES':' C:\ Program Files', ' PROGRAMFILES(X86)':' C:\ Program Files(x86)', ' PROGRAMW6432':' C:\ Program Files', ' PROMPT':' $ P $ G', ' PSMODULEPATH':' C:\ Windows \ system32 \ WindowsPowerShell \ v1.0 \ Modules \', ' PUBLIC':' C:\ Users \ Public', ' QUERY_STRING':'', ' REMOTE_ADDR':' 127.0.0.1', ' REMOTE_HOST':'', ' REQUEST_METHOD':' GET', ' RUN_MAIN':' true', ' SCRIPT_NAME':你'', ' SERVER_NAME':' nitin-PC', ' SERVER_PORT':' 8000', ' SERVER_PROTOCOL':' HTTP \ 1.1', ' SERVER_SOFTWARE':' WSGIServer \ 0.1 Python \ 2.7.3', ' SESSIONNAME':'控制台', ' SYSTEMDRIVE':' C:', ' SYSTEMROOT':' C:\ Windows', ' TEMP':' C:\ Users \ nitin \ AppData \ Local \ Temp', ' TMP':' C:\ Users \ nitin \ AppData \ Local \ Temp', ' USERDOMAIN':' nitin-PC', ' USERNAME':' nitin', ' USERPROFILE':' C:\ Users \ nitin', ' WINDIR':' C:\ Windows', ' wsgi.errors':',模式' w'在0x0000000001D761E0>, ' wsgi.file_wrapper':, ' wsgi.input' :, ' wsgi.multiprocess':错, ' wsgi.multithread':是的, ' wsgi.run_once':错, ' wsgi.url_scheme':' http', ' wsgi.version':(1,0)}> (文件不存在) 使用loader django.template.loaders.app_directories.Loader: C:\ Python27 \ LIB \站点包\ Django的\的contrib \权威性\模板\, POST:, COOKIES:{' csrftoken':' CNnHomGRMMJmik75Pi2rclMVdPjO36t9'}, META:{' ALLUSERSPROFILE':' C:\ ProgramData', ' APPDATA':' C:\ Users \ nitin \ AppData \ Roaming', ' CLASSPATH':'。; D:\ data \ Codes; C:\ Users \ nitin \ Downloads \ javapostmark \ apache-mime4j-0.6.jar; C:\ Users \ nitin \ Downloads \ javapostmark \公地编解码器-1.3.jar; C:\ Users \用户尼丁\下载\ javapostmark \共享记录-1.1.1.jar; C:\ Users \用户尼丁\下载\ javapostmark \ GSON-1.4.jar; C: \ Users \用户尼丁\下载\ javapostmark \ HttpClient的-4.0.1.jar; C:\ Users \用户尼丁\下载\ javapostmark \的HttpCore-4.0.1.jar; C:\ Users \用户尼丁\下载\ javapostmark \ httpmime-4.0 .1.jar; C:\ Users \用户尼丁\下载\ javapostmark \乔达 - 时间 - 1.6.jar;&#39 ;, ' COMMONPROGRAMFILES':' C:\ Program Files \ Common Files', ' COMMONPROGRAMFILES(X86)':' C:\ Program Files(x86)\ Common Files', ' COMMONPROGRAMW6432':' C:\ Program Files \ Common Files', ' COMPUTERNAME':' NITIN-PC', ' COMSPEC':' C:\ Windows \ system32 \ cmd.exe', ' CONTENT_LENGTH':'', ' CONTENT_TYPE':' text \ plain', ' CSRF_COOKIE':' CNnHomGRMMJmik75Pi2rclMVdPjO36t9', ' DJANGO_SETTINGS_MODULE':' dummy.settings', ' FP_NO_HOST_CHECK':'否', ' GATEWAY_INTERFACE':' CGI \ 1.1', ' HOMEDRIVE':' C:', ' HOMEPATH' \#39; \ Users \ nitin', ' HTTP_ACCEPT':' text \ html,application \ xhtml + xml,application \ xml; q = 0.9,* \ *; q = 0.8', ' HTTP_ACCEPT_CHARSET':' ISO-8859-1,utf-8; q = 0.7,*; q = 0.3', ' HTTP_ACCEPT_ENCODING':' gzip,deflate,sdch', ' HTTP_ACCEPT_LANGUAGE':' en-US,en; q = 0.8', ' HTTP_CACHE_CONTROL':' max-age = 0', ' HTTP_CONNECTION':' keep-alive', ' HTTP_COOKIE':' csrftoken = CNnHomGRMMJmik75Pi2rclMVdPjO36t9', ' HTTP_HOST':' 127.0.0.1:8000', ' HTTP_USER_AGENT':' Mozilla \ 5.0(Windows NT 6.1; WOW64)AppleWebKit \ 537.4(KHTML,如Gecko)Chrome \ 22.0.1229.94 Safari \ 537.4', ' JAVA_HOME':' C:\ Program Files(x86)\ Java \ jdk1.7.0_05;', ' LOCALAPPDATA':' C:\ Users \ nitin \ AppData \ Local', ' LOGONSERVER':' \ NITIN-PC', ' NUMBER_OF_PROCESSORS':' 2', ' OS':' Windows_NT', ' PATH':' C:\ Program Files(x86)\ Java \ jdk1.7.0_05 \ bin; C:\ Python27; C:\ Python27 \; C:\ Python27 \ Scripts&#39 ;, ' PATHEXT':' .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS; .JSE; .WSF; .WSH; .MSC', ' PATH_INFO':你' \ home \', ' PROCESSOR_ARCHITECTURE':' AMD64', ' PROCESSOR_IDENTIFIER':' Intel64 Family 6 Model 23 Stepping 10,GenuineIntel', ' PROCESSOR_LEVEL':' 6', ' PROCESSOR_REVISION':' 170a', ' PROGRAMDATA':' C:\ ProgramData', ' PROGRAMFILES':' C:\ Program Files', ' PROGRAMFILES(X86)':' C:\ Program Files(x86)', ' PROGRAMW6432':' C:\ Program Files', ' PROMPT':' $ P $ G', ' PSMODULEPATH':' C:\ Windows \ system32 \ WindowsPowerShell \ v1.0 \ Modules \', ' PUBLIC':' C:\ Users \ Public', ' QUERY_STRING':'', ' REMOTE_ADDR':' 127.0.0.1', ' REMOTE_HOST':'', ' REQUEST_METHOD':' GET', ' RUN_MAIN':' true', ' SCRIPT_NAME':你'', ' SERVER_NAME':' nitin-PC', ' SERVER_PORT':' 8000', ' SERVER_PROTOCOL':' HTTP \ 1.1', ' SERVER_SOFTWARE':' WSGIServer \ 0.1 Python \ 2.7.3', ' SESSIONNAME':'控制台', ' SYSTEMDRIVE':' C:', ' SYSTEMROOT':' C:\ Windows', ' TEMP':' C:\ Users \ nitin \ AppData \ Local \ Temp', ' TMP':' C:\ Users \ nitin \ AppData \ Local \ Temp', ' USERDOMAIN':' nitin-PC', ' USERNAME':' nitin', ' USERPROFILE':' C:\ Users \ nitin', ' WINDIR':' C:\ Windows', ' wsgi.errors':',模式' w'在0x0000000001D761E0>, ' wsgi.file_wrapper':, ' wsgi.input' :, ' wsgi.multiprocess':错, ' wsgi.multithread':是的, ' wsgi.run_once':错, ' wsgi.url_scheme':' http', ' wsgi.version':(1,0)}> (文件不存在)
答案 0 :(得分:1)
TEMPLATE_DIRS
不是可迭代的,dir应介于[]
manage.py shell
和from django.conf import settings; print settings.TEMPLATE_DIRS[0]
,即可显示django使用的路径。manage.py shell
中找到您的模板的方法是from django.template import loader; print loader.get_template('home.html')
。 Django应该告诉你它失败时尝试的模板目录。这很重要。答案 1 :(得分:0)
只需将模板路径复制并粘贴到setting.py
中。它将解决此问题。
'DIRS': ['/Users/abc/dort/dort/templates'],
享受!
答案 2 :(得分:0)
在出现错误的浏览器中,搜索'django.template.loaders.filesystem.Loader'
那里提到了django查找模板的路径。
示例:
django.template.loaders.filesystem.Loader: /code/templates/home.html (Source does not exist)
尝试在上面的相同路径中添加模板。
为避免混淆,请将模板文件夹添加到与project_name相同的目录中,并在settings.py的DIRS前面的[方括号]中添加os.path.join(BASE_DIR, 'templates')
如果您的django网站托管在docker上,则需要查看模板文件夹的确切路径,并需要在settings.py中提及它。