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>
相关推荐
lili-felicity2 分钟前
CANN批处理优化技巧:从动态批处理到流水线并行
人工智能·python
一个有梦有戏的人4 分钟前
Python3基础:进阶基础,筑牢编程底层能力
后端·python
爬山算法21 分钟前
Hibernate(88)如何在负载测试中使用Hibernate?
java·后端·hibernate
摘星编程22 分钟前
解析CANN ops-nn中的Transpose算子:张量维度变换的高效实现
python
Liekkas Kono29 分钟前
RapidOCR Python 贡献指南
开发语言·python·rapidocr
独断万古他化40 分钟前
【Spring 原理】Bean 的作用域与生命周期
java·后端·spring
玄同76541 分钟前
Python 后端三剑客:FastAPI/Flask/Django 对比与 LLM 开发选型指南
人工智能·python·机器学习·自然语言处理·django·flask·fastapi
爱吃泡芙的小白白1 小时前
环境数据多维关系探索利器:Pairs Plot 完全指南
python·信息可视化·数据分析·环境领域·pairs plot
我爱加班、、1 小时前
Websocket能携带token过去后端吗
前端·后端·websocket