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 许可协议。转载请注明出处!
相关文章
性能提升4倍!使用Granian作为Django项目的ASGI服务器
Granian是Rust写的ASGI服务器,性能比Daphne强点,但离uWSGI还差着远?静态文件支持倒是省事。开发环境够用,生产环境还是得看情况。
2025-11-22 · Django · 约 1 分钟
Django中「强行」使用MVVM设计模式
扫盲 首先带大家了解一下什么是MVVM模式: 什么是MVVM?MVVM是Model-View-ViewModel的缩写。 MVVM是MVC的增强版,实质上和MVC没有本质区别,只是代码的位置变动而已 从名字上看,MVVM比MVC架构中多了一个ViewModel,没错,就是这个ViewModel,他是MVVM相对于MVC改进的核心思想。在开发过程中,由于需求的变更或添加,项目的复杂度越来越高,代码量
2021-12-18 · Django · 约 1 分钟
Django项目引入NPM和gulp管理前端资源
前言 之前写了一篇《Asp-Net-Core开发笔记:使用NPM和gulp管理前端静态文件》,现在又来用Django开发项目了,之前我搞了一个Django的快速开发脚手架「DjangoStarter」,正好给升级一下~ 关于npm和gulp我就不多重复了,之前那篇文章都写了,直接上操作 安装依赖 安装依赖的操作跟上一篇文章是一样的,不过我这里直接提供package.json文件,复制到项目根目录里
2022-04-02 · Django · 约 1 分钟
Django-Filter介绍与刁钻需求的实现方法
Django-Filter是一个非常好用的第三方库,很好的利用了Django ORM的特性,可以使用很少的代码就扩展原有的接口,实现多种筛选功能~ 场景 Model定义的部分代码,可以看到需求模型包括了 关键词 keyword、区域 region、需求状态 require_status,这三个字段 class Require(models.Model): 需求 keyword =
2021-12-18 · Django · 约 1 分钟
讨论
共 0 条加载评论中…