How does django display the default value in a textfield to form.
<input type="text" name="{{ form.username}}" value="{{ costumer.username}}"><p>
it shows a textfield follow by costumer.username in browser, I want to have the username as default value in the textfield, How can i do that?
Use initial parameter to a form:
form = Form(initial={'username': costumer.username})
and to display input in template you need just this:
{{ form.username }}<br/>
https://docs.djangoproject.com/en/dev/ref/forms/api/#dynamic-initial-values
In your view:
myForm = MyForm(initial={'username': costumer.username })
and in the template:
{{myForm.username|safe}}
Should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With