返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
Django

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

曦远 (DealiAxy)约 4 分钟
目录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中「强行」使用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 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…