Configuring Django Static File Routing After Disabling Debug
When Django's Debug mode is turned off, requesting static files returns a 404 response code. The backend request URL is "GET /static/css/404.css HTTP/1.1" 404 1217, and the static file URL cannot be found. Static files can be obtained by configuring the static file URL and starting from the command line. URL Configuration Django static files are managed through ``. Serving static file responses is implemented via the serve() function. The configuration in url.py is as follows: fr
目录3 个章节
When Django's Debug mode is turned off, requesting static files returns a 404 response code. The backend request URL is "GET /static/css/404.css HTTP/1.1" 404 1217, and the static file URL cannot be found. Static files can be obtained by configuring the static file URL and starting from the command line.
URL Configuration
Django static files are managed through ``. Serving static file responses is implemented via the serve() function. The configuration in url.py is as follows:
from django.conf.urls import url
from django.contrib import admin
from django.contrib.staticfiles import views as view
from blog import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'home/', views.Test.as_view(), name='test'),
# 静态文件的url配置
url(r'^(?P<path>.*)$', view.serve),
]
Static Files
The static file configuration remains unchanged.
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'statics'),
os.path.join(BASE_DIR, 'bootstrap-3.3.7'),
]
Startup
Do not start via PyCharm's shortcut icon; if you start that way, the files still cannot be accessed. Start with the command:
python manage.py runserver 127.0.0.1:80 --insecure
to start, where --insecure forces Django to handle static files.
After this configuration, the static file URLs can match the corresponding static files.
_EOF_
Configuring Django Static File Routing After Disabling Debug
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
Django-Import-Export插件控制数据导入流程
前言 之前写过两篇跟这个插件有关的文章,可以回顾一下: Django数据导入导出神器django-import-export使用 Django-Import-Export插件关于外键的处理 最近有个朋友留言问我一个关于django-import-export插件的问题 为了形象表达这个问题,我举个书籍管理的例子来描述一下 数据库表 | id | name | price | | ---- |
2022-09-02 · Django · 约 1 分钟
Django快速开发实践:Drf框架和xadmin配置指北
步骤 既然是快速开发,那废话不多说,直接说步骤: 安装Djagno 安装Django Rest Framework 定义models 定义Rest framework的serializers 定义Rest framework的viewsets 配置Rest framework的router 配置管理后台admin 根据需要写template和对应的view 经过这些步骤就能得到一个具备完整的后端接
2022-09-06 · Django · 约 1 分钟
聊聊Django应用的部署和性能的那些事儿
前言 随着工作的深入,我越来越发现Python Web开发中有很多坑,也一直在羡慕AspNetCore和Go等的可执行文件部署和高性能,以及Spring生态的丰富,不过因为工作用了Django,生活还是要继续的嘛,这Django好歹也是有很大份额的Web框架,也没那么不堪,至少开发速度上就吊打一众框架了~ 在之前的文章里我介绍过使用Docker部署Django应用的方法,不过那种部署方式只适合上线
2022-05-27 · Django · 约 1 分钟
性能提升4倍!使用Granian作为Django项目的ASGI服务器
Granian是Rust写的ASGI服务器,性能比Daphne强点,但离uWSGI还差着远?静态文件支持倒是省事。开发环境够用,生产环境还是得看情况。
2025-11-22 · Django · 约 1 分钟
讨论
共 0 条加载评论中…