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 %}。这样就可以正常加载静态文件了。

实例:

{% 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>

相关推荐

  1. 视频文件出现错误

    2024-04-30 08:50:01       10 阅读
  2. django收集静态文件

    2024-04-30 08:50:01       18 阅读
  3. Django --静态文件

    2024-04-30 08:50:01       14 阅读
  4. django静态文件命名空间

    2024-04-30 08:50:01       43 阅读
  5. anylabeling 模型后出错

    2024-04-30 08:50:01       50 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-30 08:50:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-30 08:50:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-30 08:50:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-30 08:50:01       20 阅读

热门阅读

  1. llm-universe学习小记录6--开源RAG项目学习

    2024-04-30 08:50:01       11 阅读
  2. LXC的原理及应用详解(三)

    2024-04-30 08:50:01       14 阅读
  3. Github 2024-04-30 Python开源项目日报 Top10

    2024-04-30 08:50:01       8 阅读
  4. 课程34:Windows Docker部署.Net Core项目

    2024-04-30 08:50:01       9 阅读
  5. 【C++刷题】优选算法——动态规划第六辑

    2024-04-30 08:50:01       12 阅读
  6. 04.压缩与解压缩命令

    2024-04-30 08:50:01       11 阅读
  7. LXC的原理及应用详解(二)

    2024-04-30 08:50:01       11 阅读