441302925@qq.com

  • 内容:有没有人和我一样 复制上面的代码到 blog/admin.py 页面下注册,会出现报错 打不开网站,找不到什么原因,我的python是 3.8 Django是最新版的 pycharm也是最新版的2020.2 报错如下: class ArticleAdmin(admin.ModelAdmin): TypeError: 'NoneType' object is not callable D:\djangoProject1\blog\admin.py changed, reloading. INFO:django.utils.autoreload:D:\djangoProject1\blog\admin.py changed, reloading. Watching for file changes with StatReloader INFO:django.utils.autoreload:Watching for file changes with StatReloader Performing system checks... Exception in thread django-main-thread: Traceback (most recent call last): File "D:\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner self.run() File "D:\Python\Python38-32\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "D:\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "D:\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "D:\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 442, in check raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues: ERRORS: <class 'blog.admin.ArticleAdmin'>: (admin.E033) The value of 'ordering[0]' refers to 'created_time', which is not an attribute of 'blog.Article'. <class 'blog.admin.ArticleAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'tui', which is not a callable, an attribute of 'ArticleAdmin', or an attribut e or method on 'blog.Article'. <class 'blog.admin.ArticleAdmin'>: (admin.E108) The value of 'list_display[4]' refers to 'user', which is not a callable, an attribute of 'ArticleAdmin', or an attribu te or method on 'blog.Article'. <class 'blog.admin.ArticleAdmin'>: (admin.E108) The value of 'list_display[5]' refers to 'views', which is not a callable, an attribute of 'ArticleAdmin', or an attrib ute or method on 'blog.Article'. <class 'blog.admin.ArticleAdmin'>: (admin.E108) The value of 'list_display[6]' refers to 'created_time', which is not a callable, an attribute of 'ArticleAdmin', or an attribute or method on 'blog.Article'. System check identified 5 issues (0 silenced). 后面我发现是 @admin.register 这个改为 @admin.site.register 后 就报错如下 return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "D:\djangoProject1\blog\admin.py", line 8, in <module> class ArticleAdmin(admin.ModelAdmin): TypeError: 'NoneType' object is not callable 有谁解决了吗? 请教下