Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-populate password field in Django?

Is there a way to pre-populate a Django form password field so that it display something in the resulting <input type="password"> html element?

The default behavior seems to be not to display anything when the MyForm(initial = {'passfield':'something'}) is set.

I need this in order to implement an user edit form. I want to display a random string which if the user doesn't modify I will know that he does not want to change the password. So I don't think there is ANY security issue in what I'm trying to do.

like image 514
Al Bundy Avatar asked Oct 22 '12 18:10

Al Bundy


1 Answers

It seems that using the render_value argument works not just for the case listed in the Django docs and can be used:

class MyForm(forms.Form):
    password_field = forms.CharField(widget = forms.PasswordInput(render_value = True))
like image 166
Al Bundy Avatar answered Nov 16 '22 02:11

Al Bundy