You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django框架出现admin.E108与admin.E116错误,求技术解决方案

解决Django Admin的E108和E116错误

错误根源

你的Comment模型里定义的布尔字段是status,但在CommentAdmin配置中错误地写成了active,Django找不到对应字段,因此抛出报错:

<class 'blog.admin.CommentAdmin'>: (admin.E108) 'list_display[4]'的值引用'active',它不是可调用对象、CommentAdmin的属性,也不是blog.Comment的属性或方法。
<class 'blog.admin.CommentAdmin'>: (admin.E116) 'list_filter[0]'的值引用'active',它不是一个字段。

修复步骤

将admin.py中所有active的引用替换为status,修改后的CommentAdmin代码如下:

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('name', 'body', 'post', 'createdOn', 'status')  # 替换active为status
    list_filter = ('status', 'createdOn')  # 替换active为status
    search_fields = ('name', 'email', 'body')
    actions = ['approveComments']

    def approveComments(self, request, queryset):
        queryset.update(status=True)  # 替换active为status

可选优化(可选)

如果希望在Admin界面显示更友好的字段名称(比如把"Status"显示为"Active"),可以给Comment模型的status字段添加verbose_name参数:

class Comment(models.Model):
    # ... 其他字段
    status = models.BooleanField(default=False, verbose_name="Active")

内容的提问来源于stack exchange,提问作者Bastion

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 09:50:43