zoukankan      html  css  js  c++  java
  • Django 配置出错模板

    常见的出错模板有:

    404.html : [page not found] 页面未找到……
    500.html : [server error] 内部错误……

    403.html : [HTTP Forbidden] 禁止访问……

    400.html : [bad request] 页面已删除、更名、过期或暂不可用……

     

    修改如下:

    settings.py

    ALLOWED_HOSTS = ['0.0.0.0' , ]
    #debug = True
    

    urls.py

    from django.conf.urls import url , include
    from django.contrib import admin
    import audios
    
    handler404 = 'audios.views.my_custom_page_not_found_view' #HttpResponseNotFound
    handler500 = 'audios.views.my_custom_error_view'
    handler403 = 'audios.views.my_custom_permission_denied_view' # HttpResponseForbidden
    handler400 = 'audios.views.my_custom_bad_request_view'
    
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^audios/', include('audios.urls')),
    ]
    
    $ tree templates/custom/
    templates/custom/
    ├── 400.html
    ├── 403.html
    ├── 404.html
    └── 500.html
    

    audios/views.py

    def my_custom_page_not_found_view(request):
        return render_to_response('custom/404.html')
    
    def my_custom_error_view(request):
        return render_to_response('custom/500.html')
    
    def my_custom_permission_denied_view(request):
        return render_to_response('custom/403.html')
    
    def my_custom_bad_request_view(request):
        return render_to_response('custom/400.html')
    

      

    DONE DONE DONE

     

  • 相关阅读:
    [leetcode]Length of Last Word
    本周第一天
    本月第一周的第一天
    获取本周的第一天
    PHP实现今天是星期几
    mysql获取相隔时间段的数据
    在mysql中给查询的结果添加序号列
    《岛上书店》
    正则表达式:在大写字母前面加_
    Git忽略文件的三个办法
  • 原文地址:https://www.cnblogs.com/zsr0401/p/6514927.html
Copyright © 2011-2022 走看看