zoukankan      html  css  js  c++  java
  • 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. 异常   未解决

    请求影响信息如下

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

  • 相关阅读:
    MSP430的IAP程序在线编程学习
    新手入门Underscore.js 中文(template)
    关于javascript中的变量声明与赋值
    DOJO复选框操作
    添加.MSPX文件(VISTA下)
    TFS集合创建
    ExtJS的导航栏(Accordion TreePanel)
    新的开始,新的起点
    MongoDB实践之路安装
    检测一个文件是否正在使用
  • 原文地址:https://www.cnblogs.com/wangcongxing/p/13617387.html
Copyright © 2011-2022 走看看