I know in Django 1.2 we may acquire the same result using {% if value in arg %} but I need this filter in Django 1.1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | @register.filter
def is_in(value, arg):
'''It performs the same action as Python in statement.
It returns True if value is in arg, False if not or any error occur.
For example:
{{ 'abc'|is_in:'www.abc.com'}} -> 'abc' in 'www.abc.com'
x = 5
l = [3,4,5,6]
{{ x|is_in:l} -> x in l
'''
try:
return value in arg
except:
return False
|
More like this
- Form field with fixed value by roam 1 week, 2 days ago
- New Snippet! by Antoliny0919 2 weeks, 1 day ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months ago
- get_object_or_none by azwdevops 6 months, 3 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Please login first before commenting.