https://cdn1.imggmi.com/uploads/2019/7/7/c5713a4e18c508dbc4bee8371f6936af-full.png
我想将烧瓶格式数据中的值传递给图像,如图所示。我从数据库中获取信息。此外,该数据应传递给colorid形式。例如,当我从零件中选择绿色时,应在colorid零件中将其写为1。
@app.route("/editproduct/<string:id>",methods = ["GET","POST"])
def edit(id):
if request.method == "GET":
cursor = mysql.connection.cursor()
sorgu = "SELECT * FROM all_products where id = %s"
result = cursor.execute(sorgu,(id,))
if result > 0:
product = cursor.fetchone()
form = Form()
form.name.data = product["name"]
form.color.data = product["color"]
form.category.data = product["category"]
form.brand.data = product["brand"]
form.colorid.data = product["colorid"]
form.categoryid.data = product["categoryid"]
form.brandid.data = product["brandid"]
form.price.data = product["price"]
form.price_currency.data = product["price_currency"]
return render_template("product.html",form = form,product=product)
else:
return render_template("product.html")
else:
form = Form(request.form)
newName = form.name.data
newColor = form.color.data
newCategory = form.category.data
newBrand = form.brand.data
newColorid = form.colorid.data
newCategoryid = form.categoryid.data
newBrandid = form.brandid.data
newPrice = form.price.data
newPriceCurrency = form.price_currency.data
sorgu2 = """UPDATE all_products Set name = %s,color = %s,category =
%s,brand = %s,colorid = %s,categoryid = %s,brandid = %s,price =
%s,price_currency = %s where id = %s """
cursor = mysql.connection.cursor()
cursor.execute(sorgu2,
(newName,newColor,newCategory,newBrand,newColorid,newCategoryid,
newBrandid,newPrice,newPriceCurrency,id))
mysql.connection.commit()
return redirect(url_for("index"))
<form method="POST">
<div>
{{ render_field(form.name,class = "form") }}
{{ render_field(form.color,class = "form") }}
{{ render_field(form.category,class = "form") }}
{{ render_field(form.brand,class = "form") }}
{{ render_field(form.colorid,class = "form") }}
{{ render_field(form.categoryid,class = "form") }}
{{ render_field(form.brandid,class = "form") }}
{{ render_field(form.price,class = "form") }}
{{ render_field(form.price_currency,class = "form") }}
<button type="submit" class="btn btn-primary">Edit</button>
</div>
</form>