Hello there, this time i just wanna show how to use a dinamic path url in templates django. Before it, this hasbeen asked and aswered by someone in stackoverflow.
There is simply how to manage it, and usefull for templates django.
- In your
urls.py
from django.conf.urls import include, url
from . import views
urlpatterns = [
url(r'^accounts/transaksi/new/$', views.TransaksiViews().new_transaksi_member, name="new_transaksi_member_page"),
]
- In your
templates.html
, change your:request.get_full_path
<li {% if request.get_full_path == "/accounts/transaksi/new/" %}class="active"{% endif %}>
<a href="{% url "new_transaksi_member_page" %}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Kirim Transaksi
</a>
</li>
to request.resolver_match.url_name
, there is simply ro resolve from your name of url.
<li {% if request.resolver_match.url_name == "new_transaksi_member_page" %}class="active"{% endif %}>
<a href="{% url "new_transaksi_member_page" %}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Kirim Transaksi
</a>
</li>
Helpfully can help..
Refference: