'Django templates url - differentiate between same url names

in my application I've got a view called download_document which works fine using {% url 'download_document' some_id %} .

Installing a 3rd party app into the virtual environment cause trouble because this app has also the download_document view (also accepting one ID parameter) with the same urlname.

If I'd like to use both with this name, can I somehow make the difference between them? For instance using both cases in the same template file?

Python: 2.7 Django: 1.11.16 Debian .


Update #1:

my app is called infk . I tried already using

{% url 'infk:download_document' document.id %}

, but in this case I got a 500 with: u'infk' is not a registered namespace.

I also tried adding namespace to the top urls.py file:

#original
url(r'^infk/', include('infk.urls')),
#modified
url(r'^infk/', include('infk.urls', namespace="infk")),

but in this case i got back a different 500: Reverse for 'infk' not found. 'infk' is not a valid view function or pattern name.

To work the second one I'd need to change at least all reverse methods from ** reverse('infk'...) to reverse('infk:infk'...) which I don't really want.

So if I don't add namespace, is there any way to call my download_document function? (By default it calls the 3rd party app's download_document view .



Solution 1:[1]

There is a way to avoid url name conflicts. All you have to do is to add their respective namespaces before the url name. As per the docs, all you need is the following:

{% url 'myapp:view-name' %}

By using the namespaced URL resolution strategy.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bernardo Duarte