如何对表单中的一个特定元素执行HTML表单操作

时间:2014-09-19 10:01:12

标签: python html forms flask

我目前正在尝试将上传编码为单个表单而不是通过遵循flask-wtf文档中的示例进行分离,但HTML表单操作似乎是将所有表单数据发送到"上传&# 34;文件夹如下图所示。无论如何,只有在"上传"?提前谢谢。

forms.py    
images = UploadSet('images', IMAGES)

class ProductForm(Form):
    name = StringField('Design', validators=[Required()])
    series = SelectField('Collection', choices=[(c.id, c.name) for c in Series.query.all()], coerce=int)
    material = SelectField('Material', choices=[(c.id, c.name) for c in Material.query.all()], coerce=int)
    purity = SelectField('Purity', choices=[(c.id, c.name) for c in Purity.query.all()], default=['1'], coerce=int)
    description = TextAreaField('Description', validators=[Required()])
    price = IntegerField('Price', validators=[Required()])
    uploads = FileField('Gallery', validators=[FileRequired(), FileAllowed(images, 'Images only!')])
    submit = SubmitField('Add to Display')

views.py
@main.route('/admin/', methods=['GET', 'POST'])
def admin():
    form = ProductForm()
    if form.validate_on_submit():
        artwork = Artwork(name=form.name.data, series_id = form.series.data, material_id = 
        form.material.data, purity_id = form.purity.data, description = form.description.data, price = form.price.data)
        db.session.add(artwork)
        filename = secure_filename(form.uploads.data.filename)
        form.uploads.data.save('app/upload/' + filename)
        flash('The design have been posted.')
    else:
        filename = None
    return render_template('admin.html', form=form, filename=filename)

admin.html
{% block page_content %}
<div class="page-header">
    <h1>Publish your design here</h1>
</div>
{{ wtf.quick_form(form) }}
<form action="/upload/" method="POST" enctype="multipart/form-data">
{{ wtf.quick_form(form) }}
</form>
{% endblock %}

0 个答案:

没有答案