I would like to set a default value for the username and password input fields on admin/login.html. I thought to edit the login.html template but I cannot figure out how to add the default value to the input fields {{ form.username }} and {{ form.password }} which are coming from the database.
<label for="id_username" class="required">{% trans 'Username:' %}</label> {{ form.username }}
<label for="id_password" class="required">{% trans 'Password:' %}</label> {{ form.password }}
Some people use javascript to put default values but it can be done in django-forms itself. You can use
_initial_which is explained here. There are 2 ways you can put initial values as far as I know…You have two options either populate the value when calling form constructor:
form = UserForm(initial={'username': 'please enter username', 'password':'enter password'})set the value in the form definition:
username = forms.CharField(initial='please enter username')