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

Django CMS模板编辑报错:'static'标签无效,求排查HTML问题

解决Django CMS模板中“无效块标签:'static'”的问题

嘿,这个问题我太熟悉了!你遇到的「无效块标签:'static'」错误,根源其实很简单——你在模板里使用了static模板标签,但没有在模板开头加载对应的标签库。

修复步骤

只需要修改模板开头的{% load %}语句,把static标签库添加进去就行:

原来的代码开头:

{% load cms_tags menu_tags sekizai_tags %}

修改为:

{% load cms_tags menu_tags sekizai_tags static %}

为什么会报错?

Django的static标签是由django.contrib.staticfiles模块提供的,哪怕你已经在settings.py里正确配置了静态文件相关内容,在模板层面还是必须显式加载这个标签库才能使用{% static %}语法。

修改后的完整模板开头示例

{% load cms_tags menu_tags sekizai_tags static %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="{% page_attribute 'meta_description' %}">
<meta name="author" content="Life Imaging Services GmbH">
<title>{% page_attribute "page_title" %}</title>
<!-- Bootstrap core CSS -->
<link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{% static 'css/modern-business.css' %}" rel="stylesheet">
{% render_block "css" %}
</head>

这样修改后,模板就能正确识别{% static %}标签,顺利加载你的CSS和JS文件了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 17:47:38