Django TemplateDoesNotExist:account/register.html

Django TemplateDoesNotExist:account/register.html,django,django-forms,django-templates,django-registration,Django,Django Forms,Django Templates,Django Registration,我正在尝试创建自己的定制注册表。我已经在templates文件夹中创建了register.html文件,我将templates设置如下: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [Path(BASE_DIR,'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_p

我正在尝试创建自己的定制注册表。我已经在templates文件夹中创建了register.html文件,我将templates设置如下:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [Path(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',
        ],
    },
},
]
AUTH_USER_MODEL= "account.Account"
这是用于注册的views.py\u视图:

 from django.shortcuts import render, redirect
from django.contrib.auth import login, authenticate
from account.forms import RegistrationForm


def registration_view(request):
    context = {}
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            account = authenticate(email=email, password=raw_password)
            login(request, account)
            return redirect('home')
        else:
            context['registration_form'] = form
    else: #GET request
        form = RegistrationForm()
        context['registration_form'] = form
    return render(request, 'account/register.html', context)
这是我的URL.py:

 from django.contrib import admin
from django.urls import path

    from personal.views import (
    home_screen_view,
)

from account.views import (
    registration_view,
)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', home_screen_view, name="home"),
    path('register/', registration_view, name="register"),]
这就是我得到的错误

TemplateDoesNotExist: account/register.html
[21/May/2021 09:58:52] "GET /register/ HTTP/1.1" 500 73593

有人能告诉我如何解决这个问题吗?

当您要求使用具有特定路径的模板时,Django开始在多个地方查找:

  • DIRS
    列表中指定的路径
  • 在已安装应用程序的所有
    模板
    子目录中(如果
    APP_DIRS
    True
在特定情况下,Django被要求从
account/register.html
检索模板,并尝试以下路径:


  • templates/account/register.html
  • account/templates/account/register.html
  • personal/templates/account/register.html

您应该将模板文件移动到
account/templates/account/register.html
(注意account的重复),或者将呈现调用更改为
render(请求,'register.html',context)

模板/account/register.html
模板/register.html
?尝试停止
runserver
命令并再次启动它,Django有时很难注意到新文件。是的,仍然会遇到相同的错误文件
register.html
应该位于这些文件夹中的一个(相对于您的项目):
模板/
帐户/模板/帐户/
personal/templates/account/
。这些是Django正在查找您的文件的地方(我可以从您的代码中推断出什么)。请尝试将
设置中的
DIRS
更改为空列表。TEMPLATES
只是检查了我的一个项目,就这样。刚刚尝试,仍然是相同的错误@pongi是的,它类似于account/templates/register.html