hln*_*hln 4 python django django-forms
django 如何在要形成的文本字段中显示默认值。
<input type="text" name="{{ form.username}}" value="{{ costumer.username}}"><p>
Run Code Online (Sandbox Code Playgroud)
它在浏览器中显示一个文本字段,后跟costumer.username,我想在文本字段中使用用户名作为默认值,我该怎么做?
对表单使用初始参数:
form = Form(initial={'username': costumer.username})
Run Code Online (Sandbox Code Playgroud)
并在模板中显示输入,您只需要:
{{ form.username }}<br/>
Run Code Online (Sandbox Code Playgroud)
https://docs.djangoproject.com/en/dev/ref/forms/api/#dynamic-initial-values
| 归档时间: |
|
| 查看次数: |
6273 次 |
| 最近记录: |