30👍
✅
You can use the slice
filter, though I don’t think there’s an equivalent to the $length
argument.
6👍
you can use cut
filter e.g. :
{{ value }} -> 'hello world'
{{ value|cut:'hello ' }} -> 'world'
- [Django]-Filtering dropdown values in django admin
- [Django]-Cannot access django app through ip address while accessing it through localhost
- [Django]-Images from ImageField in Django don't load in template
- [Django]-Images from ImageField in Django don't load in template
- [Django]-How to test "render to template" functions in django? (TDD)
- [Django]-Itertools.groupby in a django template
2👍
As everyone felt leaving a link would be enough, I’ll add some code sample from django documents here:
slice
filter returns a slice of the list
{{ some_list|slice:":2" }}
If some_list is ['a', 'b', 'c']
, the output will be ['a', 'b']
.
- [Django]-Negating a boolean in Django template
- [Django]-How to test "render to template" functions in django? (TDD)
- [Django]-Exclude fields in Django admin for users other than superuser
1👍
See truncatechars, django docs filters:
<p>Example {{ person.names|truncatechars:20 }}</p>
- [Django]-How do I run tests against a Django data migration?
- [Django]-Substring in a django template?
- [Django]-Access web server on VirtualBox/Vagrant machine from host browser?
Source:stackexchange.com