Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I "ignore" NoReverseMatch in Django template?

Is there any way to disable throwing NoReverseMatch exceptions from url tags in Django templates (just make it silently fail, return an empty string or smth... temporarily, for development, of course)?

(I'm working on a Django project that is kind of a mess as far as things are organized (bunch of remote-workers, contractors plus the local team with lots of overlapping tasks assigned to different people and even front-end and back-end work tends to get mixed as part of the same task...) and I really need to just ignore/hide/disable the NoReverseMatch thrown by template url tags in order to efficiently do my part of the job and not end up doing other peoples' jobs in order to be able to do mine...)

like image 276
NeuronQ Avatar asked Dec 27 '22 15:12

NeuronQ


1 Answers

An alternative is using {% url ... as var %}, which doesn't raise the exception (as explained in the documentation), but doesn't render the url inline either.

You'll need to replace this:

<a href="{% url somepage %}">

with this:

{% url somepage as var %}
<a href="{{ var }}">

Depending on how many templates you've got to work with, this may or may not be the better solution.

like image 200
Gonzalo Avatar answered Dec 31 '22 12:12

Gonzalo