This is what you're aiming for when you visit the home page:


In order to achieve this you will need to:

1. Create an SQLite database with SQLAlchemy. The database needs to contain a "Movie" Table. This table should contain the following fields:

id 
title 
year 
description 
rating 
ranking
review
img_url

The title should be unique. That way you only get one entry per movie title in your ranking.

Remember, your database will be stored in the instance folder, so you'll have to create this folder.

2. Using code/DB Viewer, add a new entry to the database with the following values:

new_movie = Movie(
    title="Phone Booth",
    year=2002,
    description="Publicist Stuart Shepard finds himself trapped in a phone booth, pinned down by an extortionist's sniper rifle. Unable to leave or receive outside help, Stuart's negotiation with the caller leads to a jaw-dropping climax.",
    rating=7.3,
    ranking=10,
    review="My favourite character was the caller.",
    img_url="https://image.tmdb.org/t/p/w500/tjrX2oWRCM3Tvarz38zlZM7Uc10.jpg"
)

HINT: Be sure to remove the add entry code from step 2 after you have run the code once. Otherwise, you'll get this:

If you've set the movie title to be unique then our database will reject adding a movie with the same title more than once. Hence the "integrity" error.


SOLUTION. You won't see anything on the website just yet, but you can see your entry in the movies.db. 


3. Add second movie to your database. You can do this by re-running your python code using the snippet below.

second_movie = Movie(
    title="Avatar The Way of Water",
    year=2022,
    description="Set more than a decade after the events of the first film, learn the story of the Sully family (Jake, Neytiri, and their kids), the trouble that follows them, the lengths they go to keep each other safe, the battles they fight to stay alive, and the tragedies they endure.",
    rating=7.3,
    ranking=9,
    review="I liked the water.",
    img_url="https://image.tmdb.org/t/p/w500/t6HIqrRAclMCA60NsSmeqe9RmNV.jpg"
)


4. Make the code works so that each entry in the database is displayed correctly on the home page.

Notice how the different parts of the data are displayed:

Front:

Back:

Query the data using flask-sqlalchemy when you visit the home page.

HINT: Use .scalars() on the result from the database to get the elements in your database.

SOLUTION