Make django url tag fail silently -
Make django url tag fail silently -
the django {% url %} templatetag raises noreversematch error when can't reverse provided url. useful in development, in production, stops user dead in tracks ugly 500 error, blocking whole page, , leading them think our site broken.
template developers shouldn't able bring downwards whole site typo. want transparently override behavior that, in production only, if reverse match can't found, outputs default url, "#", , reports error our exception tracking scheme in background, still lets user go on doing without raising 500 error.
is there way replace default {% url %} tag own safer version, transparently? don't want have add together {% load my_custom_url_tag %} @ top of every single template on site, because @ point people forget, , behavior of tag otherwise same, difference how handles errors.
you can utilize built-in url tag in silent mode, seek lookup, , utilize url finds—if finds something.
from django docs:
this {% url ... var %}
syntax not cause error if view missing. in practice you’ll utilize link views optional:
{% url 'path.to.view' the_url %} {% if the_url %} <a href="{{ the_url }}">link optional stuff</a> {% endif %}
hope helps.
django django-urls django-templates
Comments
Post a Comment