在参考书中的例子(django使用的版本是1.10.3,python使用的是最新的3.8),django项目创建成功,进入项目文件夹中,使用python manage.py报runtimeerror错误:RuntimeError: class not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.AbstractBaseUser'>. Was classcell propagated to type.new?
查找了度娘,终于发现问题所在:python3.6以后的问题,如果使用依赖于__class__的零参数super super().__ method (args)或在类体内引用__class,则会引发警告
————————————————
版权声明:本文为CSDN博主「grace666」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/grace666/article/details/103568674
在django/db/models/base.py加上如下代码即可:
new_attrs = {'__module__': module}
classcell = attrs.pop('__classcell__', None)
if classcell is not None:
new_attrs['__classcell__'] = classcell
new_class = super_new(cls, name, bases,new_attrs)