在 Django 中实现 http404 [英] Implementing http404 in django

查看:34
本文介绍了在 Django 中实现 http404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 django 中找不到实现页面并查看了文档 404

Implementing page not found in django and have looked at the documentation 404

我还没有收到页面未找到错误,我在这里做什么

I do not get a page not found error as yet what ami doing here

在我的 url 代码中,我做了以下操作,

In my code in urls i have done the following,

  url(r'^$', 'site_config.views.pagenotfound')

从 django.http 导入 Http404

from django.http import Http404

 def pagenotfound(request):
   return render_to_response('polls/pagenotfound.html', {})

推荐答案

django中处理404和500的方式是:默认在templates目录下,创建一个404.html

The way you handle 404 and 500 in django is: by default, in the templates directory, create a 404.html

如果您需要自定义处理程序,只需将这些添加到 urls.py

If you need a custom handler, just add these to urls.py

handler404 = 'views.page_not_found_custom'    
handler500 = 'views.page_error_found_custom'    

按照您想要的方式设计 404.html 页面

design the 404.html page the way you want

这篇关于在 Django 中实现 http404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆