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. 異常   未解決

 

請求影響信息如下

 那位大佬解決了還請指點下 感謝


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM