Django加载静态文件出错‘staticfiles‘ is not a registered tag library.

在html文件中输入{% load staticfiles %},提示错误信息:'staticfiles' is not a registered tag library.

解决:

在 Django 中,如果要加载静态文件,应该使用 {% load static %} 而不是 {% load staticfiles %}staticfiles 模块在 Django 1.7 版本中被弃用,取而代之的是 static 模块。因此,需要将 {% load staticfiles %} 更改为 {% load static %}。这样就可以正常加载静态文件了。

实例:

html 复制代码
{% load static %}  #加载静态文件
<! DOCTYPE html>
<html lang="zh-cn">
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="{% static 'css/bootstrap.css' %}"> #加载项目根目录下statc/css文件夹中的bootstrap.css文件
    </head>
    <body>
      {% include "blog_header.html" %}
      <div class="container">
        {% block content %}{% endblock %}
      </div>
      {% include "blog_footer.html" %}
      {% block javascript %}{% endblock %}
    </body>
</html>
相关推荐
GetcharZp5 小时前
GitHub 49K+ Star!C++ 开发者必知的 JSON 神级库:从零到精通全指北
后端
xujinwei_gingko5 小时前
SpringBoot整合WebSocket
spring boot·后端·websocket
智码看视界6 小时前
现代Web开发基础:全栈工程师的起航点
前端·后端·c5全栈
程序员cxuan6 小时前
Claude Fable 5 来了
人工智能·后端·程序员
biter down6 小时前
从 0 到 1 搭建 Python 接口自动化测试框架(博客系统实战)
开发语言·python
JS菌6 小时前
手写一个 AI Agent 全栈项目:从沙箱执行到子智能体的完整实现
前端·人工智能·后端
wang09076 小时前
自己动手写一个spring之IOC_2
java·后端·spring
ltl7 小时前
推理退化:为什么大模型会输出乱码、死循环和无意义文本
后端
ltl7 小时前
架构视图与文档:C4 模型从入门到实战
后端
肖永威7 小时前
Python多业务并行计算框架插件化演进:从硬编码到动态注册
python·插件化·并行计算·动态注册