【发布时间】: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