zoukankan      html  css  js  c++  java
  • Python django 404页面配置和debug=false 静态文件配置 django版本1.10.5

    django设置404页面

    1.设置settings文件

    DEBUG = False
    
    
    ALLOWED_HOSTS = ['127.0.0.1', 'localhost']或者
    ALLOWED_HOSTS = ['*']
    

    2.配置urls文件

    from django.conf.urls import handler404, handler500
    
    
    handler404 = views.函数名称
    

    3.在views文件中定义函数page_not_found和page_error

    from django.shortcuts import render_to_response
    
    def page_not_found(request):
        return render_to_response('404.html')
    
    
    def page_error(request):
        return render_to_response('500.html')
    

    4.在app的templates下建立404.html和500.html文件(文件内就是你自定义的404或者500页面

    django debug=False

    1.在url.py 导入

    from django.conf import settings
    from django.views.static import serve
    
    urlpatterns = [
        url(r'^static/(?P<path>.*)$',serve,{'document_root': settings.STATIC_ROOT,}),
    
    ]    
    

    2.settings.py

    STATIC_ROOT ='static的本地路径/static'
  • 相关阅读:
    人 生 死 梦
    接口(三):
    接口(二):
    Mac下OpenCV开发环境配置(Terminal和Xcode)
    OcLint的使用
    分类Category的概念和使用流程
    @class
    内存管理
    点语法
    多态的概念和用法
  • 原文地址:https://www.cnblogs.com/wspblog/p/7718167.html
Copyright © 2011-2022 走看看