2017-07-14 51 views
1

我正在使用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', 
] 

This is the structure of my django project.

+0

在settings.py中,您需要添加模板路徑。 – Rahul

回答

2

似乎模板文件夾位於根目錄,所以你需要將你的設置改爲這個

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 
     }, 
    }, 
]