返回文章列表文章索引阅读全文
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项目笔记:sessions处理以及复杂对象序列化

前言:一点题外话 我发现,不更新博客的时候,不是非常忙,就是效率非常低。最近没怎么更新博客,原因是第二种= =。惭愧惭愧。 今天效率出奇的高,一天时间把PassNote后端的接口全部写完了,Django很好用,不过实际项目中还是有些框架不能实现的功能需要解决的,我比较喜欢造轮子,不过为了保证效率,还是尽量用现成的工具,减少不必要的折腾。 关于PassNote 之前应该在博客有说过,这是一个密码管理

2022-04-02 · Django · 约 1 分钟

Django+Logging:日志记录配置与使用方法

前言 日志在程序开发中是少不了的,通过日志我们可以分析到错误在什么地方,有什么异常。在生产环境下有很大的用途。在Java开发中通常用log4j,logback等第三方组件。那么在django中是怎么处理日志?django利用的就是Python提供的logging模块,但django中要用logging,还得有一定的配置规则,需要在setting中设置。 Logging模块 Logging模块为应用

2022-04-02 · Django · 约 1 分钟

DjangoAdmin使用合集

DjangoAdmin DjangoAdmin本身就是一套大而全的系统,官方文档中介绍了很多配置方法,但仍然有大量的骚操作是文档中没有的,所以遇到特殊需求的时候,求助文档不一定有用。 在我看来 DjangoAdmin 虽然能快速生成一套管理后台,但如果要做大量特殊需求的定制,其成本不亚于用 Vue/React 重新开发一套,简单的使用成本不高,但深入定制的话需要对 DjangoAdmin 的工作流

2023-04-09 · Django · 约 1 分钟

讨论

共 0 条

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

加载评论中…