python - 模板不存在于/accounts/login

标签 python django django-registration

我正在使用 django-registraion 进行用户身份验证。我确实通过 pip 安装了 django-registration 并添加到了 settings.py 文件中。但是它仍然给我模板不存在错误。错误如下:

 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.

最佳答案

模板文件夹似乎位于根目录,因此您需要将设置更改为此

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

关于python - 模板不存在于/accounts/login,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45095752/

相关文章:

python - 如何使用tensorflow进行文本分类?

python - 根据元素位置从另一列中提取某些元素

python - 为什么这个正则表达式在 python 中不起作用?它是有效的并且在 RegExr 上运行良好

python - 无法在 Linux mint 19.1 上为 python3.7.4 安装 Django 2.2.4

python - 在给定时间内禁用 django 表单字段

django - form-horizo​​ntal 不适用于 django-crispy-forms 和 django-registration-redux

python - 要列出的 Unicode 字符串

python - 从 iterable 实现 django OR 查询的最佳实践方法?

python - Django 1.8 自定义注册模板文件夹不再工作

django - django 1.5 自定义用户模型的子类化 django-registration 1.0 表单