我正在使用 Sphinx 来记录我的 Django 应用程序。我的目录树,基于这个django tutorial是:
.
├── 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。
views.py
def index(request):
return render(request, 'help/index.html', {})
urls.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" />
关于python - 如何让 django 为 Sphinx 找到特定的 css 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58903003/