Show url name on page

Asked

Viewed 28 times

0

someone knows if da to capture the name of the url on the page?

type to want to make a condition to use class="active" example:

   {% if url 'create_indicador' %}
   <li class="active">.......
   {% else %}
   <li>........
   {% endif %}

thank you in advance!

3 answers

0


I was able to do so tbm, because I ran into another problem that when I have in the url after the bar, like crete_indicator/people using == my active did not work, so in this case I only check if the string contains inside the request path.

works 100%!

{% if 'create_indicador' in request.path %}
<li class="active">.......
{% else %}
<li>........
{% endif %}

0

The get_full_path() method returns "half" of the page address, or rather returns the address of your page without the domain. For example, if the address is: http://www.site_exemplo.com.br/bla/ble/bli/ use the request.get_full_path() in your view returns /bla/ble/bli/. The big question was how to get the part http://www.site_exemplo.com.br.

How do you do that? Simple, just use the build_absolute_uri() method of the request object of your view. Done! Problem solved.

  • 1

    Edson good night, man how do I put this in my template? I thought about doing something like this ai in case I’m just guessing how it looks.... {% if 'create_indicator/' is get_full_path() %} <li class="active">.... {% Else %} <li>........ {% endif %} my url path('create_indicator/', include('Django.indicators.urls')),

  • You’ve tried it your way, it seems to work.

  • Edson worked that way {% if '/create_indicator/' == request.path %} <li class="active">....... {% Else %} <li>..... {% endif %}

-1

It worked that way

{% if '/create_indicador/' == request.path %}
<li class="active">.......
{% else %}
<li>........
{% endif %}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.