TemplateDoesNotExist错误解决

Posted wddshuai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TemplateDoesNotExist错误解决相关的知识,希望对你有一定的参考价值。

1.设置完settings的所有参数后,打开网页(http://X.X.X.X:8080/time/),报如下错误:

 

TemplateDoesNotExist at /time/

current_date.html
Request Method: GET
Request URL: http://10.159.33.17:8080/time/
Django Version: 1.8.14
Exception Type: TemplateDoesNotExist
Exception Value:
current_date.html
Exception Location: /root/anaconda/lib/python2.7/site-packages/Django-1.8.14-py2.7.egg/django/template/loader.py in get_template, line 46
Python Executable: /root/anaconda/bin/python
Python Version: 2.7.9
Python Path:
[‘/home/mysql/djcode/mysite‘,
 ‘/root/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg‘,
 ‘/root/anaconda/lib/python2.7/site-packages/Django-1.8.14-py2.7.egg‘,
 ‘/root/anaconda/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg‘,
 ‘/root/anaconda/lib/python27.zip‘,
 ‘/root/anaconda/lib/python2.7‘,
 ‘/root/anaconda/lib/python2.7/plat-linux2‘,
 ‘/root/anaconda/lib/python2.7/lib-tk‘,
 ‘/root/anaconda/lib/python2.7/lib-old‘,
 ‘/root/anaconda/lib/python2.7/lib-dynload‘,
 ‘/root/anaconda/lib/python2.7/site-packages/cryptography-0.8-py2.7-linux-x86_64.egg‘,
 ‘/root/anaconda/lib/python2.7/site-packages‘,
 ‘/root/anaconda/lib/python2.7/site-packages/Sphinx-1.2.3-py2.7.egg‘]
Server time: Fri, 2 Sep 2016 02:30:08 +0000

2.查看TEMPLATES如下:

TEMPLATES = [
    {
        ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
        ‘DIRS‘: ‘/home/mysql/djcode/mysite/templates‘,
        ‘APP_DIRS‘: True,
        ‘OPTIONS‘: {
            ‘context_processors‘: [
                ‘django.template.context_processors.debug‘,
                ‘django.template.context_processors.request‘,
                ‘django.contrib.auth.context_processors.auth‘,
                ‘django.contrib.messages.context_processors.messages‘,
            ],
        },
    },
]

3.修正的方法如下:

TEMPLATES = [
    {
        ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
        ‘DIRS‘: [os.path.join(BASE_DIR, "templates")],
        ‘APP_DIRS‘: True,
        ‘OPTIONS‘: {
            ‘context_processors‘: [
                ‘django.template.context_processors.debug‘,
                ‘django.template.context_processors.request‘,
                ‘django.contrib.auth.context_processors.auth‘,
                ‘django.contrib.messages.context_processors.messages‘,
            ],
        },
    },
]

以上是关于TemplateDoesNotExist错误解决的主要内容,如果未能解决你的问题,请参考以下文章

如何解决 django 错误:raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)

Django,TemplateDoesNotExist 错误:Heroku 找不到模板目录。如何显示它在哪里看?

TemplateDoesNotExist - Django 错误

TemplateDoesNotExist:模板路径错误

TemplateDoesNotExist 处的错误 /

Pythonanywhere 中的 TemplateDoesNotExist 错误