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

     

  • 相关阅读:
    套接字I/O函数write/read writev/readv send/recv sendto/recvfrom sendmsg/recvmsg
    套接字之recvmsg系统调用
    套接字之recv系统调用
    套接字之recvfrom系统调用
    套接字之sendmsg系统调用
    套接字之send系统调用
    数据类型
    简单的c程序分析
    c语言函数分析
    堆栈图
  • 原文地址:https://www.cnblogs.com/zsr0401/p/6514927.html
Copyright © 2011-2022 走看看