【发布时间】:2015-10-21 19:03:10
【问题描述】:
如何将表单数据和上传的图像显示到页面。就像它是一个学生申请网站,学生将在其中填写他的信息以及他的照片。因此,当他提交时,他将被重定向到另一个页面“apply.html”,其中填写了他自己的信息并在页面上显示了一张图片,有点像录取卡。
我能够将图像上传到我的“静态/上传”文件夹,并且当提交表单时,用户会被重定向到“apply.html”并填写信息,但我找不到在“上显示图像的方法”应用.html"
这是我的代码
@app.route('/form.html', methods=['GET', 'POST'])
def form():
nform = NewRegistration(request.form)
if request.method == 'POST':
if nform.validate() == False:
flash('All fields are required.')
return render_template('form.html', form=nform)
else:
try:
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
except Exception as e:
print "Form without file "+e
post = request.form['element_15'].strip()
name = request.form['element_1_1'].strip()
last = request.form['element_1_2'].strip()
Name = str(name)+ ' ' +str(last)
father = request.form['element_2'].strip()
mother = request.form['element_3'].strip()
gender = request.form['element_17'].strip()
data = {'Name' : Name, 'post' : post, 'father' : father}
return render_template("apply.html", data=data)
elif request.method == 'GET':
return render_template('form.html', form=nform)
【问题讨论】:
标签: flask flask-wtforms flask-login