繁体   English   中英

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

[英]How can make django find a specific css file forSphinx?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM