Django反向和url默认,而不是NoReverseMatch [英] Django reverse and url default instead of NoReverseMatch

查看:172
本文介绍了Django反向和url默认,而不是NoReverseMatch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置默认网址,无法找到反向匹配时使用的网址?这个想法是,如果在生产中出现打字错误,我想显示类似于404或描述性错误页面的内容,而不是获取NoReverseMatch异常。

Is it possible to set up a default URL which will be used whenever a reverse match cannot be found? The idea is that if in production there is a typo, I would like to display something akin to a 404 or a descriptive error page, instead of getting a NoReverseMatch exception.

推荐答案

模板标签网址引发异常。您可以在代码中看到:

The templatetag url raise a Exception. You can see in the code:

https://code.djangoproject.com/browser/django/trunk/django/templatetags/future.py#L117

但是,您可以创建其他模板标签(复制并粘贴90%),不会引发任何内容,并显示类似于404或描述性错误页面的内容,而不是获取NoReverseMatch异常。

But, you can create other templatetag (copy and paste 90%), that does not raise anything and "display something akin to a 404 or a descriptive error page, instead of getting a NoReverseMatch exception."

这篇关于Django反向和url默认,而不是NoReverseMatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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