python - 如何让 django 找到 Sphinx 的特定 css 文件?
问题描述
我正在使用 Sphinx 来记录我的 django 应用程序。我的目录树,基于这个django 教程是:
.
├── db.sqlite3
├── help
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── templates
│ │ └── help
│ │ ├── _images
│ │ ├── index.html
│ │ ├── _modules
│ │ ├── objects.inv
│ │ ├── _sources
│ │ │ └── index.rst.txt
│ │ └── _static
│ │ ├── css
│ │ │ ├── badge_only.css
│ │ │ └── theme.css
│ │ ├── fonts
│ │ └── js
│ │ ├── modernizr.min.js
│ │ └── theme.js
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── polls
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── users
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
├── urls.py
└── views.
在html中设置css文件的代码是:
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
这看起来像一个相对链接,但是当帮助文件在 django 中显示时没有拾取 css。
视图.py
def index(request):
return render(request, 'help/index.html', {})
网址.py
urlpatterns = [
url(r'^help/', views.index, name='index'),
]
如果页面直接加载到浏览器中,它就可以工作。
如何加载 css 文件?
解决方案
在您的 html 文件顶部指定:
{% load static %}
你的CSS:
<link rel="stylesheet" href="{% static 'css/theme.css' %}" type="text/css" />
推荐阅读
- angular - 如何向 npm pack 添加版本号?
- python - 在 django 表单中输入重复的错误消息
- google-apps-script - 谷歌表格表格图表 - 换行文本
- mongodb - 如果在 $lookup 的 $match 条件下有空结果,我该如何使用不同的条件?
- javascript - 如何在 HTML 中更改背景图像
- reactjs - React 功能组件未接收异步数据,似乎停止运行 Mid-Function
- c++ - 没有正文的 class 关键字有什么用?
- r - R 中的 API 调用优化
- scheme - 为什么(不是?(对?x)[...])比((对?x)[...])有益?
- javascript - Svelte:如何将动作传递给组件?