在參考書中的例子(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)