2015-08-23 31 views
0

我有形式定义如下烧瓶WTF的FileField值消失提交

class DogForm(Form): 
    birthdate = DateField(u'Birthdate', validators=[DataRequired(message=u"User correct form D.M.Y")], format='%d.%m.%Y') 
    image = FileField(u'Image of a dog', validators=[Optional()]) 
    submit = SubmitField(u'Save') 

这样

{{ wtf.form_field(dogForm.birthdate) }} 
{{ wtf.form_field(dogForm.image) }} 
{{ wtf.form_field(form.submit) }} 

在subbmitting模板,如果生日是在错误的形式给出,

form.validate_on_submit() 

停止验证过程并返回生日错误

视图

form = dogForm() 
if form.validate_on_submit(): 
    add_dog(form) 

return render_template("dog.html", form=form) 

我的问题是从的FileField该文件路径的重新加载的形式消失,我不能活动设置它像其他值

form.image.data = "somepath.." 
+0

请提供查看代码。 –

+0

我也有一些其他的形式,一切正常。这种行为只能在PasswordField中看到,安全性和FileField在哪里没有。我希望有一些方法可以手动设置,除了form.image.data,这显然是做别的。 – jojkos

+0

[在ASP.NET MVC验证失败后如何保持输入类型=文件字段值?](http://stackoverflow.com/questions/967916/how-to-keep-input-type-file-field -value-after-failed-validation-in-asp-net-mvc) – dirn

回答