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>
相关推荐
JavaGuide39 分钟前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
桦说编程1 小时前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
孟健1 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
格砸2 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
蝎子莱莱爱打怪2 小时前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
哈密瓜的眉毛美3 小时前
零基础学Java|第三篇:DOS 命令、转义字符、注释与代码规范
后端
用户60572374873083 小时前
AI 编码助手的规范驱动开发 - OpenSpec 初探
前端·后端·程序员
哈密瓜的眉毛美3 小时前
零基础学Java|第二篇:Java 核心机制与第一个程序:从 JVM 到 Hello World
后端
码路飞3 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python