django 如何在表单的文本字段中显示默认值。
<input type="text" name="{{ form.username}}" value="{{ costumer.username}}"><p>
它在浏览器中显示一个文本字段,后面跟着 costumer.username,我想将用户名作为文本字段中的默认值,我该怎么做?
最佳答案
对表单使用初始参数:
form = Form(initial={'username': costumer.username})
要在模板中显示输入,您只需要这样:
{{ form.username }}<br/>
https://docs.djangoproject.com/en/dev/ref/forms/api/#dynamic-initial-values
关于python - 在表单字段 Django 中显示默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16107281/