模板不存在/帐户/登录
问题描述:
我正在使用django-registraion进行用户验证。我通过pip安装了django注册并添加到settings.py文件中。但它仍然给我Templtate不存在的错误。这里的错误:模板不存在/帐户/登录
TemplateDoesNotExist at /accounts/login/
registration/login.html
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/?next=/
Django Version: 1.11.3
Exception Type: TemplateDoesNotExist
Exception Value: registration/login.html
Exception Location: C:\Python34\lib\site- packages\django\template\loader.py in select_template, line 53
下面的代码:
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.views import login, logout
from chat.views import index
from django.conf.urls import include
urlpatterns = [
url('^', include('django.contrib.auth.urls')),
url(r'^admin/', admin.site.urls),
url(r'^$',index, name='homepage'), # The start point for index view
url(r'^accounts/login/$', login, name='login'), # The base django login view
url(r'^accounts/logout/$', logout, name='logout'), # The base django logout view
在settings.py文件
:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'chat',
'registration',
]
答
似乎模板文件夹位于根目录,所以你需要将你的设置改为这个
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/templates/',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list of context processors
],
'debug': True
},
},
]
在settings.py中,您需要添加模板路径。 – Rahul