text: from flask import Flask, render_template, request, redirect, url_for
  from flask_sqlalchemy import SQLAlchemy
  
  
  app = Flask(__name__)
  
  
  # Create database
  app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///books.db"
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  db = SQLAlchemy(app)
  
  
  # Create table
  class Book(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(250), unique=True, nullable=False)
      author = db.Column(db.String(250), nullable=False)
      rating = db.Column(db.Float, nullable=False)
  
  
  db.create_all()
  
  
  @app.route('/')
  def home():
      all_books = db.session.query(Book).all()
      return render_template('index.html.jinja', books=all_books)
  
  
  @app.route("/add", methods=['GET', 'POST'])
  def add():
      if request.method == 'POST':
          new_book = Book(
              title=request.form['title'],
              author=request.form['author'],
              rating=request.form['rating']
          )
          db.session.add(new_book)
          db.session.commit()
          return redirect(url_for('home'))
  
      return render_template('add.html.jinja')
  
  
  @app.route("/edit", methods=['GET', 'POST'])
  def edit():
      if request.method == "POST":
          book_id = request.form["id"]
          book_to_update = Book.query.get(book_id)
          book_to_update.rating = request.form["rating"]
          db.session.commit()
          return redirect(url_for('home'))
  
      book_id = request.args.get('id')
      book_selected = Book.query.get(book_id)
      return render_template("edit_rating.html.jinja", book=book_selected)
  
  
  @app.route("/delete")
  def delete():
      book_id = request.args.get('id')
      book_to_delete = Book.query.get(book_id)
      db.session.delete(book_to_delete)
      db.session.commit()
      return redirect(url_for('home'))
  
  
  if __name__ == "__main__":
      # app.run(debug=True)
      app.run()
  