我目前正在尝试构建我的第一个 django 应用程序,一个简历网站。我在尝试启动应用程序时收到此错误。
<class 'mainapp.admin.CertificateAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'is_active', which is not a callable, an attribute of 'CertificateAdmin', or an attribute or method on 'mainapp.Certificate'.
这是我在 models.py 文件中与“证书”相关的内容(包括注释):
`类证书(models.Model): 类元: verbose_name_plural = '证书' verbose_name = '证书'
date = models.DateTimeField(blank=True, null=True) # When the certificate was earned
name = models.CharField(max_length=50, blank=True, null=True) # Name of the certificate
title = models.CharField(max_length=200, blank=True, null=True) # Title or description of the certificate
description = models.CharField(max_length=500, blank=True, null=True) # Additional details about the certificate
is_active = models.BooleanField(default=True)`
这就是我的 admin.py 文件中的内容:
@admin.register(Certificate) class CertificateAdmin(admin.ModelAdmin): list_display = ('id', 'name', 'title', 'is_active') # Display 'id', 'name', and 'is_active' fields
ChatGPT 到目前为止没有任何帮助,只有循环答案以确保正确调用“is_active”,我不确定是不是,看起来是这样(我是一个初学者)。
我正在遵循 youtube 视频中的说明(是的,我从去年开始就一直在学习 python 和 django,没有盲目遵循!),“is_active”部分应该在那里,根据 chatgpt 我尝试删除它这使得应用程序启动,但有其他错误(页面没有显示,是的,我已经准备好了所有 css 和 html 文件)。
在 admin.py 文件中尝试一下:
而不是使用装饰器@admin.register
类CertificateAdmin(admin.ModelAdmin): list_display = ('id', '名称', '标题', 'is_active')
admin.site.register(证书,CertificateAdmin)