Skip to content

Latest commit

 

History

History
 
 

flask3

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Server Side Programming exercises (Python, Flask), Part III.

Exercise #0: Set up MySQL

  • Install MySQL on your local machine.
  • Create a MySQL database called dat310.
  • Create a table called movies with the following structure:
    • imdb_id VARCHAR(20) we'll use the IMDB movie IDs as a unique identifier and PRIMARY KEY
    • title VARCHAR(40)
    • year INT
    • rating DOUBLE
    • synopsis TEXT
  • Add some movies to the table.
  • You may create the table and add data using the movies.sql script.
  • Install MySQL Connector/Python
    • on the command line: conda install mysql-connector-python

Exercise #1: Listing movies

Update Exercise 4 from the last lecture such that movies are loaded from the MySQL database.

Specifically,

  • Remove the MOVIES const; this data will need to be loaded from the database.
  • Make a connection to the database (make sure the DB and the movies table have been created).
  • Make a SELECT query that returns all movies from the table.
  • Notice that are not storing the IMDB URLs in the database. You'll need to generate the links to the IMDB movie pages from the imdb_id field. Do that in the movies.html template file (i.e., not in app.py).

The output should look exactly as before: Exercise1

Exercise #2: Movie details

Generate a separate "details" page for each movie.

  • Remove the links to the IMDB profile page from the movie listing. Instead, make the title of the movie a link to /movie/<movie_id>, where movie_id refers to the id field in the movies table.
  • Make a layout.html file that contain a common header and footer. The movie listing and movie details pages should extend layout.html.

Exercise2/1 Exercise2/2