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

已安装crispy forms,Django模板仍无法渲染的问题求助

解决Django中crispy forms找不到bootstrap4模板的问题

报错信息

TemplateDoesNotExist at /accounts/create/
Error during template rendering
In template [PATH_NAME]\cryptoProj\backend\templates\signup.html, error at line 21
bootstrap4/uni_form.html

对应报错代码行:

<p>{{ form | crispy }}</p>

解决步骤

  • 安装bootstrap4模板依赖
    若使用django-crispy-forms 2.0及以上版本,需单独安装bootstrap4模板支持:

    pip install crispy-bootstrap4
    
  • 更新INSTALLED_APPS配置
    在项目settings.py中,除已添加的crispy_forms,补充加入crispy_bootstrap4:

    INSTALLED_APPS = [
        # 其他已注册应用
        'crispy_forms',
        'crispy_bootstrap4',
    ]
    
  • 指定crispy模板包
    在settings.py末尾添加配置,明确使用bootstrap4模板:

    CRISPY_TEMPLATE_PACK = 'bootstrap4'
    
  • 重启Django服务
    停止当前运行的开发服务器,重新启动以加载新配置。

额外检查

  • 若使用django-crispy-forms 1.x版本,无需单独安装crispy-bootstrap4,但仍需设置CRISPY_TEMPLATE_PACK = 'bootstrap4'
  • 确认项目模板路径配置正常,确保Django能检索到crispy相关模板文件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 16:58:39