24 lines
476 B
Python
24 lines
476 B
Python
# Searches for shows using Ajax with JSON
|
|
|
|
from cs50 import SQL
|
|
from flask import Flask, jsonify, render_template, request
|
|
|
|
app = Flask(__name__)
|
|
|
|
db = SQL("sqlite:///shows.db")
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return render_template("index.html")
|
|
|
|
|
|
@app.route("/search")
|
|
def search():
|
|
q = request.args.get("q")
|
|
if q:
|
|
shows = db.execute("SELECT * FROM shows WHERE title LIKE ? LIMIT 50", "%" + q + "%")
|
|
else:
|
|
shows = []
|
|
return jsonify(shows)
|