我的view.py
form_data = {
'message':data_dict['message']
'contract_image': data_dict['contract_image']}
form = AddMcc(form_data)
print form['message'] // <input name="message" type="text" value="apple" /> (apple equal data_dict['message'] I got)
print form['contract_image'] // <input class=".." name="contract_image" type="file" />
return render(request, 'hellow.html', {'form': form, 'contract_image': data_dict_alipay['contract_image']})
我的模板
<div class="am-form-group am-u-lg-8">
<p>{{ form.subject }}</p>
<p>{{ form.message }}</p>
</div>
<div class="am-form-group am-form-file am-u-lg-8">t
<div class="upload_image am-u-lg-2">
<button type="button" class="am-btn am-btn-default am-btn-sm">
{{ form.contract_image }}
<img class="image_thumb" src="{{ MEDIA_URL }}{{ contract_image}}" />
<button>edit</button>
</div>
</div>
form.py
contract_image = forms.ImageField(
required = True,
widget=forms.FileInput(
attrs={
'id': 'id_contract_image'
}
),
)
此模板供用户编辑其infos.template显示信息属于用户。如果用户想要更改消息或contract_image,他们可以直接编辑它们。现在我的问题是,如果用户不想更改他的contract_image,但是form.contract_image仍然需要它中的东西(require = true),如果不是空的话,如何设置它的默认值?