【问题标题】:Link to stylesheets in django template链接到 Django 模板中的样式表
【发布时间】:2020-06-06 05:37:43
【问题描述】:

我正在开发一个大型 Django 网站,目前正在添加 html 模板。

这是主要部分的文件树

C:.
+---forums
|   |   admin.py etc
|   |   
|   +---migrations
|   |   |   ...
|   |           
|   +---templates
|   |   \---forums
|   |           help-style.css
|   |           help.html
|   |           home-style.css
|   |           home.html

我一直在使用<link rel="stylesheet" type="text/css" href="home-style.css"> 链接到样式表字节,当我这样做时会导致此错误

Not Found: /forums/home-style.css
[22/Feb/2020 07:38:14] "GET /forums/home-style.css HTTP/1.1" 404 2702

我尝试过使用{% static 'home-style.css' %}{% load staticfiles %} 但他们没有工作

提前致谢!

【问题讨论】:

  • 我建议您阅读有关 Django 希望您如何处理静态文件的文档:docs.djangoproject.com/en/3.0/howto/static-files。您不能将静态文件放在模板目录中。他们需要在您的应用程序中进入单独的static 目录。

标签: python html css django django-templates


【解决方案1】:

<link rel="stylesheet" type="text/css" href="{% static 'forums/main.css' %}">

我按照solarissmoke 的建议查看了静态文件,其他感兴趣的人可以查看here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2015-12-19
    • 2015-02-25
    • 2013-11-14
    相关资源
    最近更新 更多