【问题标题】:How to add external css/js in django2.2如何在django2.2中添加外部css/js
【发布时间】:2019-07-20 09:24:04
【问题描述】:

使用 django 时如何将外部 css/js 添加到我的 html 模板中

我已经尝试过一些以前提出的问题的回复,但似乎它们已经过时了,下面是我遵循的程序之一

# after making sure the installed app has contrib.static then i make a file called static/my_apps/my.css
{%loadstatic%}
    <link rel='stylesheet' href="{%static 'my_apps/my.css' %}"> 
     # i also tried {%loadstaticfile%} but none work

【问题讨论】:

    标签: django


    【解决方案1】:

    创建项目时,您有一个特定的 django 文件夹层次结构和创建模板文件夹的位置,在同一位置创建名称为 static 的文件夹并添加所有静态文件(js/css /图像)在里面。然后在访问时使用 static 标签在模板中访问它。 {%static 'path/to/your/static/files'%} 这个路径 django 引擎从静态文件夹中获取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 2015-09-07
      • 2017-07-02
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      相关资源
      最近更新 更多