django 模板中的 css

标签 css django django-templates django-staticfiles

我在我的 django 模板中使用 css 时遇到问题,

在我的 settings.py 中我有这个:

BASE_DIR = os.path.abspath(os.path.dirname(__file__) + '/')
STATIC_URL = BASE_DIR + '/static/'

在我的路径中,我有文件夹 "static/css/home_css.css"

在我的模板 home.html 中,我有链接标签:

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/home_css.css" media="all" />

但它无法渲染 de css。 如果有人知道会发生什么,请

最佳答案

STATIC_URL 不应指向文件系统中的路径。 STATIC_ROOT 应该。

import os

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = "/static/"

关于django 模板中的 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12627432/

相关文章:

python - Django 休息框架嵌套序列化无法正常工作

javascript - Django 渲染一个 "in exception"的页面而不是一个可以帮助调试的页面

css - 在 R Shiny 中更改侧边栏菜单项颜色

html - 2 列最小高度 100% 困难

javascript - 按类型单击 Selenium 中的元素

python - Django 表单在表单字段后添加 <div>

django - 如何获取模板中表单的外键值?

html - 水平居中导航/ Logo 的问题

python - 如何在基于类的 View 中进行排序

python - Django Rest Framework,更新嵌套的序列化数据