MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / edit

Function edit

Crud_in_flask/main.py:45–67  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

43
44@app.route('/<int:id>/edit/', methods=('GET', 'POST'))
45def edit(id):
46 products = get_products(id)
47
48 if request.method == 'POST':
49 title = request.form['title']
50 price = request.form['price']
51
52 if not title:
53 flash('Title is required!')
54
55 elif not price:
56 flash('Content is required!')
57
58 else:
59 conn = get_db_connection()
60 conn.execute('UPDATE products SET title = ?, price = ?'
61 ' WHERE id = ?',
62 (title, price, id))
63 conn.commit()
64 conn.close()
65 return redirect(url_for('index'))
66
67 return render_template('edit.html', products=products)
68
69
70@app.route('/<int:id>/delete/', methods=('POST',))

Callers

nothing calls this directly

Calls 2

get_productsFunction · 0.85
get_db_connectionFunction · 0.85

Tested by

no test coverage detected