views:

128

answers:

2

I need to display a piece of HTML only if a variable value appears in a list. I know that Django 1.2 has an 'in' operator. But I am working on a Google App Engine app. Is there a workaround I can use?

A: 

If what you need to know is whether you should render a piece of HTML, and you are going to reuse this rule in other templates, you may try to use django.template.RequestContext and make it an accessable status variable in templates in 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 request.

Satoru.Logic
+1  A: 

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

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

deno