Django 1.1 equivalent of 'in' operator

I need to display a piece of HTML only if the value of the variable appears in the list. I know that Django 1.2 has an "in" statement. But I'm working on a Google App Engine application. Can I use a workaround?

+4
source share
2 answers

You can use your own template tag to achieve it or put it in your controller logic.

Take a look at this snippet: http://www.djangosnippets.org/snippets/302/

+1
source

If you need to know if you want to display part of the HTML, and you are going to use this rule in other templates, you can try using django.template.RequestContext and make it available to the status variable in the templates that need.

 def context(request): return {'render_a_panel' : request.user.username in ('Jim', 'Tom')} 

Of course, this only works if your rule is based on a query.

0
source

Source: https://habr.com/ru/post/1306665/


All Articles