zoukankan      html  css  js  c++  java
  • 在线教育平台-全局配置页面(13)

    (1)MxOnline/urls.py

    复制代码
    from MxOnline.settings import STATIC_ROOT
    
    urlpatterns = [
    #静态文件
        re_path(r'^static/(?P<path>.*)', serve, {"document_root": STATIC_ROOT }),
    ]
    
    
    # 全局404页面配置
    handler404 = 'users.views.pag_not_found'
    # 全局500页面配置
    handler500 = 'users.views.page_error'

    (2)MxOnline/settings.py

    复制代码
    DEBUG = False
    
    ALLOWED_HOSTS = ['*']
    
    
    #静态文件
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')

    (3)users/views.py

    复制代码
    from django.shortcuts import render_to_response
    def pag_not_found(request):
        # 全局404处理函数
        response = render_to_response('404.html', {})
        response.status_code = 404
        return response
    
    def page_error(request):
        # 全局500处理函数
        from django.shortcuts import render_to_response
        response = render_to_response('500.html', {})
        response.status_code = 500
        return response
    复制代码

    说明:

    • 404和500,生成环境汇总,必须设置debug = False
    • 一旦debug改为false,django就不会代管你的静态文件,所以这里要设置一个url处理静态文件
  • 相关阅读:
    Nim or not Nim? hdu3032 SG值打表找规律
    Maximum 贪心
    The Super Powers
    LCM Cardinality 暴力
    Longge's problem poj2480 欧拉函数,gcd
    GCD hdu2588
    Perfect Pth Powers poj1730
    6656 Watching the Kangaroo
    yield 小用
    wpf DropDownButton 源码
  • 原文地址:https://www.cnblogs.com/topass123/p/12951377.html
Copyright © 2011-2022 走看看