I have an urls.py with this line:
url(r'^logout/$', 'django.contrib.auth.views.logout', name="auth_logout"),
In my template tag i have this line:
<a href="{% url auth_logout %}">Logout</a>
Now, I would like to add the next_page param to the url templatetag, but I can't get it to work. I have tried this:
{% url auth_logout request.path %}"
...and this:
{% url auth_logout request,request.path %}
But none of them works. How can I provide the function with the optional next_page paramter usinging the url templatetag?
Thanks!
A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template.
{% url 'contact-form' %} is a way to add a link to another one of your pages in the template. url tells the template to look in the URLs.py file.
{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.
The URL template tag is a typical type of Tag in the Django Template Language framework. This tag is specifically used to add View URLs in the Template Files. In the HTML Template file, URL tags are used with the Anchor, <a href> attribute of HTML, which handles all the URLs in HTML.
For what it's worth, I use this:
<a href="{% url auth_logout %}?next=/">Logout</a>
Two things:
So, first modify your url to accept next_page Your URLConf needs modification to pass in the next page, something like this for a hard-coded redirect:
url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}, name='auth_logout'),
and one parameterized result:
url(r'^logout/(?P<next_page>.*)/$', 'django.contrib.auth.views.logout', name='auth_logout_next'),
And then modify your template to pass in the next_page
<a href="{% url auth_logout_next /some/location %}">Logout</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With