bharal
bharal

Reputation: 16194

django check within template if the current url has a particular word in it

Similar to this question:

Django template, if tag based on current URL value

only I want to check if the url has a word in it - you know, like

if a.find(b) == -1

how can i do this?

Upvotes: 15

Views: 17644

Answers (2)

user6679035
user6679035

Reputation:

Forget request parameters and use:

{% if 'search_term' in request.GET %}
  Hello World!
{% endif %}

Upvotes: 2

Scott Woodall
Scott Woodall

Reputation: 10676

Perhaps the in operator?

{% if b in request.path %}
    hello world!
{% endif %}

If that doesn't accomplish what you need then move the logic to your view or create a custom template tag.

Upvotes: 34

Related Questions