13

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?

Community
  • 1
  • 1
bharal
  • 15,461
  • 36
  • 117
  • 195

2 Answers2

31

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.

EternalHour
  • 8,308
  • 6
  • 38
  • 57
Scott Woodall
  • 10,456
  • 6
  • 39
  • 37
1

Forget request parameters and use:

{% if 'search_term' in request.GET %}
  Hello World!
{% endif %}
Cartucho
  • 3,257
  • 2
  • 30
  • 55