开发者

Django 1.1 equivalent of the 'in' operator

开发者 https://www.devze.com 2022-12-26 05:54 出处:网络
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 G开发者_StackOverflow中文版oogle App Engine app. Is t

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 G开发者_StackOverflow中文版oogle App Engine app. Is there a workaround I can use?


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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消