Please create the froshims.db for the following flask app: Implements a registration…
- User
Please create the froshims.db for the following flask app:
Implements a registration form, storing registrants in a SQLite database, with support for deregistration
from cs50 import SQL from flask import Flask, redirect, render_template, request
app = Flask(name)
db = SQL("sqlite:///froshims.db")
SPORTS = [ "Basketball", "Soccer", "Ultimate Frisbee" ]
@app.route("/") def index(): return render_template("index.html", sports=SPORTS)
@app.route("/deregister", methods=["POST"]) def deregister():
# Forget registrant id = request.form.get("id") if id: db.execute("DELETE FROM registrants WHERE id = ?", id) return redirect("/registrants")@app.route("/register", methods=["POST"]) def register():
# Validate submission name = request.form.get("name") sport = request.form.get("sport") if not name or sport not in SPORTS: return render_template("failure.html") # Remember registrant db.execute("INSERT INTO registrants (name, sport) VALUES(?, ?)", name, sport) # Confirm registration return redirect("/registrants")@app.route("/registrants") def registrants(): registrants = db.execute("SELECT * FROM registrants") return render_template("registrants.html", registrants=registrants)
- Assistant
To create the
froshims.dbdatabase for the Flask application described, you need to define aregistrantstable that will store the data for each registrant. Here's how you can create it using SQLite:- Open a terminal or command prompt.
- Run
sqlite3 froshims.dbto create the database file and enter the SQLite shell. - At the SQLite prompt, execute the following SQL command to create the
registrantstable:
CREATE TABLE registrants ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, sport TEXT NOT NULL );
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.