Reputation: 2316
I want to create a custom filter for django templates. I've got some currency pairs (which are links) that I pass to my html page so I need to check if current url is equal to a currency pair from my list, then I gotta skip it.
For example, my url is:
https://website.com/usd/eur/
So if there's a pair USD/EUR, it won't be shown on my page.
To do this, I need to loop over all pairs and compare them to request.path value. So, how can I get it within my template tags ?
Upvotes: 0
Views: 699
Reputation: 2277
You can directly receive request
into template tags like -
@register.simple_tag(name='new_tag')
def new_tag(request):
path = request.path
....
and then in your html use it like {% new_tag request %}
.
Upvotes: 2