最近开始实习,刚刚接触django!在我按文档写到搜索页面时,总是出现TemplateDoesNotExist at /search/错误。stackoverflow搜一搜发现是忘记写模版搜索路径。在setting.py加入下面部分:
<span style="font-size:14px;background-color: rgb(255, 255, 255);">import os.path
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
)</span>
问题解决!
另外,下面是关于
<span style="font-size:14px;background-color: rgb(255, 255, 255);">os.path.join(os.path.dirname(__file__),</span>
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如:
python d:/pythonSrc/test/test.py
那么将输出 d:/pythonSrc/test
(2).当"print os.path.dirname(__file__)"所在脚本是以相对路径被运行的, 那么将输出空目录,比如:
python test.py
那么将输出空字符串