Django settings DEBUG=False 无法加载资源文件

liunx 环境下这样配置正常的  开发环境配置遇到请求头问题,见文章末 

1.为什么要把DEBUG=False  不是我闲着没事干,因为请求如果报错会提示出错误详情页面,里面含有代码错误提示信息,这样就对系统的安全性造成了影响

django应用时如果设置了 DEBUG = True,那么django便会自动帮我们对静态文件进行路由;

但是当我们设置DEBUG = False后,这一功能便没有了,此时静态文件就会出现加载失败的情况,想要让静态文件正常显示,我们就需要配置静态文件服务了。

下载所有的资源文件到项目的static文件夹下

python manage.py collectstatic

 

 

修改项目文件夹下的urls.py

"""OpenTheDoor URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from app import views

from django.conf import settings
from django.conf.urls.static import static

from django.conf.urls import url
from django.views import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('helloWorld/', views.helloWorld),
    path('helloH5/', views.helloH5),
    url(r'^static/(?P<path>.*)$', static.serve,
        {'document_root': settings.STATIC_ROOT}, name='static')
]

运行效果

错误页面不会在提示异常信息

 

 

 

 

1.开发环境 遇到的巨坑

windows10

python3.7

django3.1

django-simpleui ==2020.7

 

 

* Refused to execute script from '<URL>' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. 异常   未解决

 

请求影响信息如下

 那位大佬解决了还请指点下 感谢

posted @ 2020-09-05 11:52  汪丛兴  阅读(701)  评论(2编辑  收藏  举报