Login

Custom template filter remove words at beginning of a string

Author:
quevon24
Posted:
September 1, 2016
Language:
Python
Version:
1.9
Score:
0 (after 0 ratings)

Filter to remove words at the beginning of a string

Example:

Myvar: "My name is Arthur and django si awesome"

{{myvar|wordremoveb:5}}

Output: "django is awesome"

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@register.filter(is_safe=True)
@stringfilter
def wordremoveb(value, arg):
	if len(value.split()) > int(arg):
		words = value.split()
		wordsuni = [x.encode('utf-8') for x in words][int(arg):]
		final = ' '.join(wordsuni)
	else:
		final = value
	return final

More like this

  1. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 3 weeks, 4 days ago
  2. Python Django CRUD Example Tutorial by tuts_station 1 month, 1 week ago
  3. Browser-native date input field by kytta 2 months, 3 weeks ago
  4. Generate and render HTML Table by LLyaudet 3 months ago
  5. My firs Snippets by GutemaG 3 months, 1 week ago

Comments

Please login first before commenting.