-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql-test.py
More file actions
33 lines (26 loc) · 946 Bytes
/
sql-test.py
File metadata and controls
33 lines (26 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
from flask import Blueprint, request, redirect, render_template, url_for
from marketplace.db import get_db
bp = Blueprint('listings', __name__, url_prefix='/listings')
@bp.route('/')
def index():
cur = get_db().cursor()
cur.execute(
'SELECT id, title, description'
' FROM listings'
)
listings = cur.fetchall()
return render_template('listings/index.html', listings=listings)
@bp.route('/create', methods=('GET', 'POST'))
def register():
if request.method == 'POST':
title = request.form['title']
description = request.form['description']
db = get_db()
cur = db.cursor()
sql = "INSERT INTO listings (title, description) VALUES ('%s', '%s')" % (title, description)
print(sql, file=sys.stdout)
cur.execute(sql)
db.commit()
return redirect(url_for('listings.index'))
return render_template('listings/create.html')