python - 如何让 django 为 Sphinx 找到特定的 css 文件?

标签 python css django

我正在使用 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/

相关文章:

python - 无法访问在GCE上运行在0.0.0.0上的Flask应用程序

python 在 try-except 中递减时行为不明确

javascript - 将类添加到最近的 ul

html - 如何使用-webkit-transform : rotateX(); 使隐藏的面孔从顶部出现

django - 在 django-rest-framework 中使用 .to_representation() 和 .to_internal_value?

Python编程: Classes

python - 将行转换为 pandas 中列下的值列表

javascript - 如果用户调整在 fullpage.js 上创建的窗口的大小,如何显示水平滚动条

jquery - 如何序列化发布到 django 后端的数组

java - Playframework 和 Django