It was necessary to write a function that updates the product in the online store, but for some reason only the picture is updated. html template:
{% extends "layout.html" %} {% block content %} <h1>Update this product:</h1> <div class="product"> <form method="POST" action="{{ url_for('update_product', product_id = product.id) }}" enctype="multipart/form-data"> {{ form.csrf_token }} <table> <td> <img src="{{ url_for('static', filename='product_pics/' + product.picture) }}" height="250px" width="250px"> <br> {{ form.picture }} </td> <td> <p id="product_name">{{ form.name }}</p> <hr> <p id="product_category"> Category: {{ form.category_id }}</p> <p id="product_description"> Product description: {{ form.description }}</p> <p id="product_price"> Price: {{ form.price }}$</p> {{ form.submit }} </td> </table> </form> </div> {% endblock content %}
And the function itself:
@app.route('/update/<int:product_id>', methods=['GET', 'POST']) def update_product(product_id): if 'ADMIN' not in session: abort(403) product = Product.query.get_or_404(product_id) form = UpdateProductForm() form.description.data = product.description form.name.data = product.name form.price.data = product.price form.category_id.data = product.category_id if form.validate_on_submit(): update_data = {'description': form.description.data, 'name': form.name.data, 'price': form.price.data, 'category_id': form.category_id.data} if form.picture.data: update_data['picture'] = save_picture(form.picture.data) Product.query.filter_by(id=product.id).update(update_data) db.session.commit() return redirect(url_for('update_product', product_id=product.id)) return render_template('update_product.html', product=product, categories=categories, form=form)
Please tell me what may be wrong here. I know that I already asked a similar question, but there is already really extreme measures, because I tried EVERYTHING (I use sqlalchemy if that).