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