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>
相关推荐
哎呦没22 分钟前
大学生就业招聘:Spring Boot系统的架构分析
java·spring boot·后端
_.Switch41 分钟前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
一个闪现必杀技1 小时前
Python入门--函数
开发语言·python·青少年编程·pycharm
小鹿( ﹡ˆoˆ﹡ )1 小时前
探索IP协议的神秘面纱:Python中的网络通信
python·tcp/ip·php
卷心菜小温2 小时前
【BUG】P-tuningv2微调ChatGLM2-6B时所踩的坑
python·深度学习·语言模型·nlp·bug
陈苏同学2 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
唐家小妹2 小时前
介绍一款开源的 Modern GUI PySide6 / PyQt6的使用
python·pyqt
杨哥带你写代码2 小时前
足球青训俱乐部管理:Spring Boot技术驱动
java·spring boot·后端
羊小猪~~3 小时前
深度学习项目----用LSTM模型预测股价(包含LSTM网络简介,代码数据均可下载)
pytorch·python·rnn·深度学习·机器学习·数据分析·lstm
AskHarries3 小时前
读《show your work》的一点感悟
后端