v-model通常您可以通过以下方式获取手动创建的输入字段:<input class="form-control mb-2" name="username" v-model="username" type="text" placeholder="username" autocomplete="off"><input class="form-control" type="password" v-model="password" placeholder="password">但是,如何抓取并放置v-modelDjango 通过模型表单自动生成的字段?<form method="post"> {% csrf_token %} {{ user_form }} <button class="btn btn-primary mt-3">Register</button></form>
1 回答
缥缈止盈
TA贡献2041条经验 获得超4个赞
您可以在您的forms.py
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = '__all__'
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
for name, field in self.fields.items():
# add v-model to each model field
field.widget.attrs.update({'v-model': name})
添加回答
举报
0/150
提交
取消