环境:Ubuntu18.04LTS
IDE:Jetbrain Pycharm 2018pro
Django:jango version 2.2.4
1、urls.py 路径映射文件
'Specifying a namespace in include() without providing an app_name ' django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
原来代码为:
path('user/', include('user.urls', namespace='user')),
更改为:
path('user/', include(('user.urls', 'user'), namespace='user')), # 用户模块
参考博客
https://blog.csdn.net/zoulonglong/article/details/79612973
2、忘记加什么了吧
RuntimeError at /home/register_over
You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to localhost:8000/home/register_over/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.
结尾加"/".
参考博客:
https://blog.csdn.net/feng88724/article/details/7221925
3、版本问题:
?: (2_0.W001) Your URL pattern 'active/(?P<token>.*)' [name='active'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().
解决:
导入:
from django.urls import path, re_path
将:
path('active/(?P<token>.*)', ActiveView.as_view(), name='active'), # 用户邮箱激活,token是取到口令的名字
改成:
re_path(r'^active/(?P<token>.*)$', ActiveView.as_view(), name='active'), # 用户邮箱激活,token是取到口令的名字
4、又是版本问题吧,Django的默认的AbstractUser的注意问题
按住Ctrl+鼠标点击查看源码,默认字段有:
- id :默认递增
- password:默认加密
- last_login:默认NULL
- is_super:默认0
- username:默认None
- first_name:默认None
- last_name:默认None
- email:默认None
- is_staff:默认False
- is_active:默认True
问题:注册一个账户,使用邮箱激活,要使用到默认的is_active字段,但是默认是True,所以在开始注册用户的时候改成了False,目的是想通过邮件激活,但是在使用其默认的authenticate()函数做验证的时候,username和password都对,但是查出的用户竟是None,原因就是 : django2.1版本以后authticate函数也会对用户的is_active进行判断,如果is_active为false,则也会返回None。
解决:知道新特性,知道返回None的原因还有可能是is_actice为false。
参考博客:
https://blog.csdn.net/qq_33445330/article/details/92078480