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

Wagtail CMS添加banner_title后启动服务报AttributeError错误

问题原因

报错信息已明确标注错误根源:AttributeError: module 'django.db.models' has no attribute 'Charfield',属于字段类名大小写拼写错误。
Django ORM的字符串字段正确类名为CharField(末尾字母F为大写),你的代码中写为小写f的Charfield,调用不存在的属性触发了报错。

修复方案

修改home/models.py中banner_title字段的定义代码即可:

# 错误写法
banner_title = models.Charfield(max_length=100, blank=False, null=True)
# 修正后写法
banner_title = models.CharField(max_length=100, blank=False, null=True)

后续操作

修改保存后依次执行以下命令即可正常运行项目:

  • 生成迁移文件:python3 manage.py makemigrations
  • 执行数据库迁移:python3 manage.py migrate
  • 启动开发服务:python3 manage.py runserver

额外提示

你代码中还有一处可提前修正的问题:Wagtail的Page类指定模板的属性为单数template,不是你写的复数templates,同步修改可避免后续模板加载报错:

# 错误写法
templates = "home/home_page.html"
# 修正后写法
template = "home/home_page.html"

内容的提问来源于stack exchange,提问作者Alessio Li Volsi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.16 09:36:08