gpt4 book ai didi

python - Django - 在模板中引用静态文件

转载 作者:太空狗 更新时间:2023-10-29 19:35:27 24 4
gpt4 key购买 nike

我在模板中引用静态文件时遇到困难。我正在使用 Twitter Bootstrap 并将 Bootstrap 文件(css、img、js)放在 mysite/static 中。

我已根据 this tutorial 设置了 STATIC_URLSTATIC_ROOTTEMPLATE_CONTEXT_PROCESSORS .我运行了 ./manage.py collectstatic 复制了 72 个文件。我还在我的模板 (index.html) 文件中添加了以下模板标签,但这没有用。

{% load staticfiles %}
<link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen"/>

任何有关如何引用文件以便 Bootstrap 样式返回到模板的帮助将不胜感激!

最佳答案

应该是

{% load static %}

然后是类似的东西

<!-- path -->
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet" type="text/css">
<!--->

完整性更新

文件夹结构

  • 项目
  • 应用1
  • 应用2
  • myproj_public
  • 静态的
    • CSS
      • bootstrap.css
    • js
      • xyz.js

设置文件

STATIC_ROOT = os.path.join(os.path.abspath(
os.path.join(PROJECT_ROOT, 'myproj_public', 'static')), '')

STATIC_URL = '/static/'

关于python - Django - 在模板中引用静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14013436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com