Lynn Chang
Lynn Chang

Reputation: 79

restricting characters in a string in django

I will like to find out how do i restrict the job.description, a string to a certain number of characters? (I want to limit it to 3 rows in my .html).

template(.html)

{{ job.description }}

forms.py

 class Meta:
        model = Job

models.py

description = db.StringProperty(multiline=True, verbose_name='Description:')

Upvotes: 0

Views: 383

Answers (1)

Arnaud
Arnaud

Reputation: 1815

There is no built-in filter to limit a string to a certain number of characters, but you can limit to a certain number of words:

{{ job.description|truncatewords:20 }}

http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#truncatewords

If you really want to restrict to a number of characters, you will have to write your own custom filter.

Upvotes: 2

Related Questions