Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django 1.7更改了模板名称now TemplateDoesNotExist错误_Python_Html_Django_Templates_Django Templates - Fatal编程技术网

Python Django 1.7更改了模板名称now TemplateDoesNotExist错误

Python Django 1.7更改了模板名称now TemplateDoesNotExist错误,python,html,django,templates,django-templates,Python,Html,Django,Templates,Django Templates,因此,我将注册模板的名称从user_form.html更改为register.html。我还在urls.py文件中对其进行了更改,以反映新名称,但是,当我尝试转到注册页面时,我得到以下信息: Exception Type: TemplateDoesNotExist Exception Value:web/user_form.html Template-loader postmortem Django tried loading these templates, in this order

因此,我将注册模板的名称从user_form.html更改为register.html。我还在urls.py文件中对其进行了更改,以反映新名称,但是,当我尝试转到注册页面时,我得到以下信息:

Exception Type: TemplateDoesNotExist 
Exception Value:web/user_form.html 

Template-loader postmortem

Django tried loading these templates, in this order:

Using loader django.template.loaders.filesystem.Loader:

Using loader django.template.loaders.app_directories.Loader:

../swl/root/lib/pythpy2.7.egg/django/contrib/admin/templates/web/user_form.html (File does not exist)

../django/contrib/auth/templates/web/user_form.html (File does not exist)

../templates/web/user_form.html (File does not exist)

..tastypie/templates/web/user_form.html (File does not exist)

../bootstrap3/templates/web/user_form.html (File does not exist)

../web/templates/web/user_form.html (File does not exist)
为什么模板加载器仍在寻找旧文件名

编辑:这是我的注册url:

url(r'register/?$”,
UserCreate.as_view(),
{
“模板名称”:“accounts/register.html”
},

name='register'),
尝试将所有文件中的所有
user\u form.html
替换为
registation.html
。您可以使用文本编辑器或IDE的
Find/replace in files
功能(或类似功能)

url
更改为:

url(r'register/?$',
    UserCreate.as_view(template_name='accounts/register.html'),
    name = 'register')

当没有显式声明名称时,基于类的视图将尝试使用默认模板名称。(CreateView使用(appname)/(model)\u form.html)您可以选择:

  • 使用默认名称命名模板
  • 在URL中指定模板(如Vladimir的回答)
  • 在视图代码中指定模板名称,如下所示:

    类UserCreate(CreateView):

  • 希望这有助于重新启动apache服务器。 对于Ubuntu服务器20:

    /etc/init.d/apache2 restart
    

    显示您在URL.py中更改的内容。谢谢@valdimir,我这样做了,但仍然得到错误。@user5852854尝试更改
    UserCreate.as_view(…)
    。我会将其更改为什么?先生,您太棒了-谢谢!
    /etc/init.d/apache2 restart