How to go to a url in django regardless of the way we are?

0

I created a menu in a base file that is visible regardless of the page we are on,

        <p> Tela de perfil <a href="perfil/">Perfil</a></p>

The problem is that when we are on the same page and click on the same link, the "Profile" and duplicate giving an error,

How can I put to go to a page that is independent if I'm already in it, or on a different path?

    
asked by anonymous 17.08.2016 / 01:28

2 answers

1

What the Puam Dias replied is correct. Just remember that to use this tag it is necessary to name the route in the urls.py file

urlpatterns = [
    url(r'^perfil/$', perfil_function, name='perfil'),
]

It is the name = 'profile' attribute that allows you to do this in the template:

<a href="{% url 'perfil' %}">Perfil</a>
    
20.10.2016 / 18:31
0

It is not recommended that you use urls in this way, as this may lead to silent errors in your application. If one day you end up changing your url to 'profile-some-thing', when accessing this template, it will continue to be rendered normally without acknowledging the error. Only when you click on the link will the error be displayed.

Try to call urls with django tags:

<p>Tela de perfil <a href="{% url 'perfil' %}">Perfil</a></p>

or

<p>Tela de perfil <a href="{% url 'namespace:perfil' %}">Perfil</a></p>

In case your url is inside a namespace app.

    
19.08.2016 / 20:18