我不知道如何将 css 包含到我的 html 中。我的元素中有一个应用程序,它有自己的模板文件夹。我想要sample.css
进入我的html。
类似于 <link rel="stylesheet" type="text/css" href="{% %}">
的内容
不太确定在 {% %}
之间放什么
结构:
/proj
/app
/templates
sample.css
sample.html
这是我的 template_dirs:
TEMPLATE_DIRS = (
os.path.join(BASE_DIR,'templates'),
os.path.join(BASE_DIR,'home/templates'),
os.path.join(BASE_DIR,'gallery/templates'),
os.path.join(BASE_DIR,'contact/templates'),
os.path.join(BASE_DIR,'aboutme/templates'),
)
如果需要任何其他信息。请告诉我!
更新结构
/proj
/app
/static
/css
sample.css
/templates
sample.html
最佳答案
css
文件以及 js
文件和图像均被视为 static files
.
通常的方法是使用django.contrib.staticfiles
内置的django应用程序来管理静态文件。
如果您正确设置应用程序,您的链接
将如下所示:
<link rel="stylesheet" type="text/css" href="{% static 'sample.css' %}">
关于css - 在 Django 中导入应用程序 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23480014/