我的 Django 版本 3.1.7,跟着视频做的时候遇到这些问题并解决,仅供参考:
1. 在 第一次 访问 /accounts/register/ 时(还没配置 LOGIN_REDIRECT_URL 和 SIMPLE_BACKEND_REDIRECT_URL),需要确保没有任何用户登录。如果有,请先注销;否则,就不会显示注册页面,而是出错,原因是会自动跳转到 http://127.0.0.1:8002/accounts/profile/,显然我们还没 这个 /accounts/profile/ 页面。
2. 执行 ./manage.py migrate 会有一个警告:
WARNINGS:
?: (2_0.W001) Your URL pattern '^accounts/' has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().
原因是视频中的 url 用法已经被 deprecated,需要换成 re_path。
我看了 作者的 https://gitee.com 里面的 代码,实际是已经 更新为 re_path了,大家可以去参考 https://gitee.com/geektime-geekbang/django/blob/master/recruitment/urls.py#L72, 避免上述警告。
展开
作者回复: 感谢分享总结
5
任宇鹏
2022-04-18
老师我这儿一直提示 No module named 'registrationdjango'
改如何解决
老师我输入/accounts/register/为什么回车就变这个 /accounts/profile/ 提示没有匹配
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/profile/
Using the URLconf defined in recruitment.urls, Django tried these URL patterns, in this order:
admin/
joblist/ [name='joblist']
^accounts/ ^register/closed/$ [name='registration_disallowed']
^accounts/ ^register/$ [name='registration_register']
^accounts/ ^login/$ [name='auth_login']
^accounts/ ^logout/$ [name='auth_logout']
^accounts/ ^password/change/$ [name='auth_password_change']
^accounts/ ^password/change/done/$ [name='auth_password_change_done']
^accounts/ ^password/reset/$ [name='auth_password_reset']
^accounts/ ^password/reset/complete/$ [name='auth_password_reset_complete']
^accounts/ ^password/reset/done/$ [name='auth_password_reset_done']
^accounts/ ^password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$ [name='auth_password_reset_confirm']
The current path, accounts/profile/, didn't match any of these.