DJango 2.0 request.path

437 views
Skip to first unread message

Michael Schietzsch

unread,
Dec 11, 2017, 7:11:20 AM12/11/17
to Django users
Hi,

I am pretty new to Django (and therefore python). I started to write a website with Django 1.11 and now tried to migrate it to 2.0
I got most working with the help of the new documentation, but I have a problem with request.path usage in a template. It worked fine with 1.11 but not with 2.0. I was not able to find that anything changed with request.path in 2.0
Here is the template snippet:


{% url 'profile' as profile_url %} {% if request.path == profile_url %}
<button type="button" class="btn btn-outline-success btn-sm active" onClick="javascript:history.go(-1);">{% user_display user %}</button>
{% else %}
<a class="btn btn-outline-success btn-sm" href="/profile" role="button">{% user_display user %}</a>
{% endif %}


What it does is, change a button, depending on the current URL. In practice:
The button is locate in a ever present nav bar. 
If you are on your profile (/profile) than the button will be in active state, and a click will go one back (sort of)
If not, the buttin not active and will on klick send you to your profile

Currently is will never be in the if true situation.

I hope you can help me
Thanks
Regards
Michael

p.s.: I thought I already posted this, but could not find it, so here as a repost. If it shows up twice, I am very sorry and will punish my browser thoroughly ;-)

Michael Schietzsch

unread,
Dec 11, 2017, 8:43:19 AM12/11/17
to Django users
Works  with

{% if request.path == '/profile/' %}

I kind of forgot that I used a URL module with 1.11...
Reply all
Reply to author
Forward
0 new messages