Shi*_*ome 8 django django-authentication
我正在尝试根据本教程使用用户身份验证构建一个简单的网站,但遇到了上述错误。按照说明,我设置了一个网址如下:
url('^accounts/', include('django.contrib.auth.urls'))
Run Code Online (Sandbox Code Playgroud)
我收到此错误作为回应:'auth' 不是注册的命名空间所以我尝试注册一个命名空间,如教程存储库所示:
url('^accounts/', include('django.contrib.auth.urls', namespace="auth")),
Run Code Online (Sandbox Code Playgroud)
然后我收到错误:在 include() 中指定命名空间而不提供 app_name
我意识到本教程使用的是 django 1.8.3,但我使用的是 2.0。当我在 virtualenv 中切换到相同的 django 版本时,问题得到了解决,但我现在不得不更改项目中的许多其他内容以防止其崩溃。有什么方法可以在不需要 django 1.8 的情况下修复?谢谢。
对于 Django 2.0 语法应该是这样的
from django.urls import path
path('accounts/', include('django.contrib.auth.urls')),
<li><a href="{% url 'auth:login' %}">Login</a></li>#do not use this in any template
<li><a href="{% url 'login' %}">Login</a></li>#use this in your template
Run Code Online (Sandbox Code Playgroud)
Django 2.0 中的 URL 路由语法已更改,也许可以尝试这样做:
from django.urls import path
path('accounts/', include('django.contrib.auth.urls')),
Run Code Online (Sandbox Code Playgroud)