django - How to serve another static root in Django for html pages?
问题描述
The typical configuration serves two static roots:
http://www.example.org/static/
http://www.example.org/media/
This is STATIC_URL
and MEDIA_URL
.
I would like to add a third one to host static files build with Sphinx:
http://www.example.org/docs/
I know I could configure this on the level of the web server. Is it also possible to configure this on the level of Django?
Here is my python package, that implements Sphinx with Django templates and renders it to static pages. A kind lightweight read-the-docs. Still in an early state, yet working.
解决方案
像为静态文件一样构建一个 url 怎么样?该DOCS_ROOT
设置应该是您设置中的字符串。
from django.urls import re_path
from django.views.static import serve
from django.conf import settings
urlpatterns += [
re_path(r'^docs/(?P<path>.*)', serve, {'document_root': settings.DOCS_ROOT})
]
推荐阅读
- php - 我无法将 POST 请求从 android volley 发送到 php
- performance-testing - 为负载运行器生成报告 pdf 的命令行方式
- jquery - Xamarin Android jQuery AJAX 在发布模式下不起作用
- django - google 的 Django-rest-framework-social-oauth2 错误
- excel - 在关闭 Excel 更新文件时使用 VBA 发送电子邮件或 Skype 消息
- machine-learning - 如何在 PYTORCH 中进行 2 层嵌套 FOR 循环?
- angular - “找不到路径控制”但无法弄清楚原因 - Angular 5
- javascript - 如何在javascript中将对象中的所有字符串变为大写
- anaconda - “conda install pandas-datareader”不工作
- python - Pyqt4年龄计算器不在标签上输出