我正在使用 Flask 在网站上工作。在数据库中我的图像类型 blob 和我使用 flask-mysql 库。我想将图像上传到数据库并从那里显示,但是当我尝试显示时,我的输出在“goster.html”中为无
这是我的上传表单:
class UploadForm(Form):
billcontent = StringField("Bill Content")
bill = FileField("File")
这里是'/deneme':
@app.route("/deneme",methods = ["POST","GET"])
@login_required
def deneme():
form = UploadForm(request.form)
if request.method == "POST":
billcontent = form.billcontent.data
bill = form.bill.data
company = get_current_user_company()
cursor = mysql.connection.cursor()
sorgu = "Insert into deneme(billcontent,bill,company) VALUES(%s,%s,%s)"
cursor.execute(sorgu,(billcontent,bill,company,))
mysql.connection.commit()
cursor.close()
flash("{} faturası başarıyla eklendi!".format(billcontent))
return redirect(url_for("index"))
return render_template("deneme.html",form=form)
在这里'/ goster':
@app.route("/goster")
@login_required
def goster():
cursor = mysql.connection.cursor()
sorgu = "Select * From deneme "
result = cursor.execute(sorgu)
if result>0:
image = cursor.fetchone()
return render_template("goster.html",image=image)
else:
return render_template("goster.html")
deneme.html:
{% extends "layout.html" %}
{% block middleside %}
{% from "includes/formhelpers.html" import render_field %}
<form method = "POST" enctype="multipart/form-data">
{{ render_field(form.billcontent,class = "form-control") }}
{{ render_field(form.bill,class = "form-control") }}
<button type="submit">Upload Bill</button>
</form>
{% endblock middleside %}
goster.html:
{% extends "layout.html" %}
{% block middleside %}
{{image.bill}}
{% endblock middleside %}