views:

45

answers:

2

I am eager to know whether any filter is available for displaying all the text as * like this

mytext = 'raja'

{{ mytext|password }} should show ****

How can we do this. plz help

+3  A: 

Easy. Do this:

{% for char in mytext %}*{% endfor %}

That said, can I ask you where you are displaying the password? Usually passwords are not displayed on screen. If you want to display it in a form you can use a PasswordInput widget.

As @Ars said it is a bad idea to reveal the length of the password. You might want to display a random number of asterisks instead.

Manoj Govindan
@Manoj Govindan : I guess that this involves password masking and is such a bad idea the way it has been asked. +1 for directing him to the widget.
pyfunc
Sir, May i Know why password masking is bad. I am only returning no of * to the browsers as (****)
Rajasekar
+1  A: 

is this really a password? Then it seems like a bad idea -- do you want to reveal that the password is 4 characters long? Just print 4 (or 5 or whatever) asterisks straight in the template always.

Otherwise, I wouldn't bother with a filter. Simply pass in a string of asterisks through the context:

mytext = 'raja'
ctx = Context({'mytext': '*' * len(mytext)})
t = Template('password: {{ mytext }}')
s = t.render(ctx)
ars