if not existstitle message Movie title could not be deleted title does not

If not existstitle message movie title could not be

This preview shows page 3 - 4 out of 4 pages.

if not exists(title): message = "Movie " + title+ " could not be deleted, title does not exist in database" else: try: cnx = mysql.connector.connect(user=username, password=password, host=hostname, database=db) except Exception as exp: print(exp) cur= cnx.cursor() query = ("DELETE FROM movies WHERE lower(title) = '%s'" % (title.lower(),)) cur.execute(query) cnx.commit() message = "Movie " + title + " successfully deleted" return render_template('index.html', message=message, entries=None) @app.route('/search_movie', methods=['GET']) def search_movie(): db, username, password, hostname = get_db_creds() try: cnx = mysql.connector.connect(user=username, password=password, host=hostname, database=db) except Exception as exp: print(exp) cur= cnx.cursor() actor = request.args.get('search_actor') query = ("SELECT * FROM movies WHERE lower(actor) = '%s'" % (actor.lower(),)) cur.execute(query) listings = [dict(title=row[2], year=row[1], actor=row[4]) for row in cur.fetchall()] message = None if len(listings) == 0: listings = None message = "No movies found for actor " + actor return render_template('index.html', message=message, listings=listings) @app.route('/highest_rating', methods=['GET']) def highest_rating(): db, username, password, hostname = get_db_creds() try: cnx = mysql.connector.connect(user=username, password=password, host=hostname, database=db) except Exception as exp: print(exp) cur= cnx.cursor() query = ("SELECT * FROM movies ORDER BY rating DESC") cur.execute(query) entries = [dict(title=row[2], year=row[1], actor=row[4], director=row[3], rating=row[6]) for row in cur.fetchall()] message = None
Image of page 3
if len(entries) == 0: entries = None message = "No movies found" return render_template('index.html', message=message, entries=entries) @app.route('/lowest_rating', methods=['GET']) def lowest_rating():
Image of page 4

You've reached the end of your free preview.

Want to read all 4 pages?

  • Spring '17
  • Gurvinder
  • CNX, flask import request , Movies

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture