Py学习  »  问与答

手动创建的TEMPLATE_DIRS中一直出问题,求帮助

取个昵称不够长 • 10 年前 • 8129 次点击  

手动创建的TEMPLATE_DIRS中: 一开始是这样写的: '/home/tooweakchen/dblog/templates', 后来改成是这样写的: os.path.join(BASE_DIR,'./dblog/templates'), 这个templates是与manage.py同级,但是两者报的错误相同,如下所示:

TemplateDoesNotExist at / index.html Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.8 Exception Type: TemplateDoesNotExist Exception Value:
index.html Exception Location: /usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/template/loader.py in render_to_string, line 138 Python Executable: /usr/bin/python2.7 Python Version: 2.7.6 Python Path:
['/home/tooweakchen/dblog', '/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg', '/home/tooweakchen/dblog', '/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/autopep8-1.1.1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/pep8-1.6.2-py2.7.egg', '/home/tooweakchen/.eclipse/org.eclipse.platform_3.8_155965261/plugins/org.python.pydev_3.9.2.201502050007/pysrc/pydev_sitecustomize', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg', '/usr/lib/python2.7/lib-old', '/usr/local/lib/python2.7/dist-packages/setuptools-0.6c11-py2.7.egg'] Server time: Mon, 11 May 2015 00:01:31 +0800 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: /usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/contrib/admin/templates/index.html (File does not exist) /usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/contrib/auth/templates/index.html (File does not exist)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1075
 
8129 次点击  
文章 [ 7 ]  |  最新文章 9 年前
hustmck
Reply   •   1 楼
hustmck    9 年前

@Janvn 谢谢!

edsion-weibo
Reply   •   2 楼
edsion-weibo    10 年前

你这是没看文档啊,官方文档的关于templates的overview里,写着呢

Janvn
Reply   •   3 楼
Janvn    10 年前

直接改动TEPMLATES下的app_dirs,和dirs就ok了,app_dirs设置成false,dirs列表中放入templates路劲就行了,搞定!

Janvn
Reply   •   4 楼
Janvn    10 年前

是的啊,我用的也是.1.8的版本,我把app_dirs都设置能flase了,TEMPLATE_DIRS设置了还是找到啊,晕,只好把templates放在应用文件夹下了,总感觉不爽啊 啊啊啊 啊

773743943
Reply   •   5 楼
773743943    10 年前

看到你的问题,我特地注册的帐号回答。1.8中改版了,不再支持TEMPLATE_DIRS这个选项,具体内容你看这里http://segmentfault.com/a/1190000002754242 我也是叫这个问题搞毛过了。

取个昵称不够长
Reply   •   6 楼
取个昵称不够长    10 年前

@kinegratii 我只能默默的说声,按照你的来,也是这个错误,昨晚弄了一晚上,也问了别人,无论怎么改都是这个错误.我的时django1.8版本,是不是版本的问题啊??

kinegratii
Reply   •   7 楼
kinegratii    10 年前

参考 http://kinegratii.com/articles/2015-01-20-the-structure-of-django-project

settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, templates).replace('\\', '/'),
)

templates目录和manage.py同一级

pro/
    --pro/
    --app1/
    --app2/
    --templates/
        |--index.html
   --manage.py