Skip to content Skip to sidebar Skip to footer

Is There Any Filter In Django To Display Asterisks (*) Instead Of Text

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?

Solution 1:

Easy. Do this:

{% forchar 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.

Solution 2:

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)

Post a Comment for "Is There Any Filter In Django To Display Asterisks (*) Instead Of Text"