django中的/ admin中找不到模板

时间:2018-06-06 12:22:02

标签: django

当我提供链接http://127.0.0.1:8000/admin/时,它会自动重定向到http://127.0.0.1:8000/admin/login/?next=/admin/并显示错误

TemplateDoesNotExist at /admin/login/

admin/login.html

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version:     2.0.6
Exception Type:     TemplateDoesNotExist
Exception Value:    

admin/login.html

Exception Location:     /media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/lib/python3.5/site-packages/django/template/loader.py in select_template, line 47
Python Executable:  /media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/bin/python
Python Version:     3.5.2
Python Path:    

['/media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite',
 '/media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/lib/python35.zip',
 '/media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/lib/python3.5',
 '/media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/lib/python3.5/plat-x86_64-linux-gnu',
 '/media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/lib/python3.5/lib-dynload',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/media/nimish/WINDOWS/Users/Home/engineerbabu/user_interface/mysite/venv/lib/python3.5/site-packages']

Server time:    Wed, 6 Jun 2018 12:15:54 +0000

我的模板设置为: -

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],

2 个答案:

答案 0 :(得分:0)

您必须将'OPTIONS'放在列表的最开头TEMPLATES

TEMPLATES = [
{
    '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',
        ]
    }
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,

您似乎无法在示例中打印整个列表,因此请保留它并将'OPTIONS'移至顶部。

答案 1 :(得分:0)

你在settings.py安装的应用程序

中有'django.contrib.admin'吗?
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
  ]