Sunday, May 30, 2010

Re: how to show blank spaces at the start of string in django templates

On May 29, 7:47 am, Ogi Vranesic <o...@redcor.ch> wrote:
> Hi
>
> I formated with python numbers like e.g.:
>
> "   3457.50"
> " 11450.25"
>
> but my problem is to show them correctly one below the other
> in a column by django templates
> because the blank spaces are ignored.
> I tried with the filter escape, however it does not work.
>
> A solution would be to loop over the characters in string like:
>
> <td>{% for c in number_string %}{% if c == ' ' %} {% else %}{{ c }}{% endif %}{% endfor %}</td>
>
> and so to replace blank space with   but this is very cumbersome.
>
> Can somebody tell me if we here have a simple and elegant solution?
> Thanks in advance and best regards
> Ogi

Use Django's template filters! :D
use {{ c | rjust:8 }}
rjust is right-justification. It requires an integer argument (or
string that can be cast as an integer) that represents the size of the
field.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment