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

Function create

Crud_in_flask/main.py:25–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23
24@app.route('/create/', methods=('GET', 'POST'))
25def create():
26 if request.method == 'POST':
27 title = request.form['title']
28 price = request.form['price']
29
30 if not title:
31 flash('Title is required!')
32 elif not price:
33 flash('Content is required!')
34 else:
35 conn = get_db_connection()
36 conn.execute(
37 'INSERT INTO products (title, price) VALUES (?, ?)', (title, price))
38 conn.commit()
39 conn.close()
40 return redirect(url_for('index'))
41 return render_template('create.html')
42
43
44@app.route('/<int:id>/edit/', methods=('GET', 'POST'))

Callers

nothing calls this directly

Calls 1

get_db_connectionFunction · 0.85

Tested by

no test coverage detected