Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get URL name in template?

Tags:

django

I tried to print this in the template, but it renders blank. Whats the correct way to get URL name in template?

{{ request.resolver_match.url_name }}

I wanted it to highlight something in the top bar (if path is 'admin-stuff' add highlight class).

like image 989
Jesvin Jose Avatar asked Nov 14 '14 07:11

Jesvin Jose


1 Answers

In the application settings TEMPLATE_CONTEXT_PROCESSORS must include

"django.core.context_processors.request"

for the request to appear in the template context.

like image 146
Jesvin Jose Avatar answered Oct 13 '22 01:10

Jesvin Jose