社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

请问各位,我在setting里面设置了模板的路径,但是页面显示还是模板文件不存在的错误,何解???急。。。。。。

342013708 • 11 年前 • 7401 次点击  

Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/time/

Django Version: 1.4.2 Python Version: 2.7.0 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

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

Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 111. response = callback(request, callback_args, *callback_kwargs) File "F:\workspace\mysite\mysite\views.py" in current_datetime 22. t = get_template('current_datetime.html') File "C:\Python27\lib\site-packages\django\template\loader.py" in get_template 145. template, origin = find_template(template_name) File "C:\Python27\lib\site-packages\django\template\loader.py" in find_template 138. raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /time/ Exception Value: current_datetime.html

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/329
 
7401 次点击  
文章 [ 5 ]  |  最新文章 11 年前
happydagui
Reply   •   1 楼
happydagui    11 年前

TEMPLATE_LOADERS这是模板加载器设置,设置了路径之后,其实路劲的意义是相对路径,是绝对路径,还是相对于应用的路径,是由加载器设定的。按照

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.eggs.Loader',
    'django.template.loaders.app_directories.Loader',
)

的设置,首先假定是一个文件系统的绝对路径,然后是python的eggs库路径,最后是django app的路径,按照先后顺序去找模板,直到找到为止。

Py站长
Reply   •   2 楼
Py站长    11 年前

@我BEN庸俗

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.eggs.Loader',
    'django.template.loaders.app_directories.Loader',
)

模板路径设置对了吗?

我BEN庸俗
Reply   •   3 楼
我BEN庸俗    11 年前

@342013708 楼主怎么解决的啊?我也出现了同样的错误

342013708
Reply   •   4 楼
342013708    11 年前

@BeginMan 问题解决了,谢谢

BeginMan
Reply   •   5 楼
BeginMan    11 年前

是不是路径设置错了啊、、