Modern Application Development I, Quiz 2
Consider the schema for the 'student' table created in SQLite database using flask-sqlalchemy.
CREATE TABLE "student" ( "s_id" INTEGER, "roll_number" TEXT NOT NULL UNIQUE, "first_name" TEXT NOT NULL, "last_name" TEXT NOT NULL, PRIMARY KEY("s_id" AUTOINCREMENT));What will be the output of the flask_sqlalchemy command given below?
>>> s1 = Student(roll_number = "M01", first_name = "John", last_name = "Doe")>>> db.session.add(s1)>>> s2 = Student(roll_number = "M02", first_name = "John", last_name = "Luther")>>> db.session.add(s2)>>> s3 = Student(roll_number = "M03", first_name = "Harry", last_name = "Doe")>>> db.session.add(s3)>>> db.session.commit()>>> user1= Student.query.filter_by(first_name="John").first()>>> user1.first_name= "Harry">>> user1.last_name= "Luther">>> db.session.commit()>>> s1 = Student.query.all()>>> for student in s1:... print(student.first_name)... print(student.last_name)...Consider the schema for the `'student'` table created in SQLite database using `flask-sqlalchemy`. CREATE TABLE "student" ( "s_id" INTEGER, "roll_number" TEXT NOT NULL UNIQUE, "first_name" TEXT NOT NULL, "last_name" TEXT NOT NULL, PRIMARY KEY("s_id" AUTOINCREMENT) ); What will be the output of the `flask_sqlalchemy` command given below? >>> s1 = Student(roll_number = "M01", first_name = "John", last_name = "Doe") >>> db.session.add(s1) >>> s2 = Student(roll_number = "M02", first_name = "John", last_name = "Luther") >>> db.session.add(s2) >>> s3 = Student(roll_number = "M03", first_name = "Harry", last_name = "Doe") >>> db.session.add(s3) >>> db.session.commit() >>> user1= Student.query.filter_by(first_name="John").first() >>> user1.first_name= "Harry" >>> user1.last_name= "Luther" >>> db.session.commit() >>> s1 = Student.query.all() >>> for student in s1: ... print(student.first_name) ... print(student.last_name) ... Consider the following flask application. from flask import Flask, abort app = Flask(__name__) users = ["admin", "user_1", "user_2", "user_3"] @app.route('/home/<string:username>', methods = ['POST']) def home(username): if username in users: return f"<h1>Hello {username}, Welcome!</h1>" else: abort(404) @app.errorhandler(404) def user_error_1(error): return "<h1>The user you are looking for is invalid.</h1>" @app.errorhandler(405) def user_error_2(error): return "<h1>Please check the web request.</h1>" app.run() If the application is running locally on `http://127.0.0.1:5000`. What will be rendered on the browser for url `http://127.0.0.1:5000/home/user_4` ? Consider the following flask app. Given that `test_request_context()` allows text to be printed on the terminal, which of the following statements is/are correct? from flask import Flask, url_for app = Flask(__name__) @app.route('/home') def index(): return 'Mad-I Student Data' @app.route('/student/<student_name>/<int:student_id>') def profile(student_name,student_id): return f'Student Name:{student_name},Student ID:{student_id}' with app.test_request_context(): #== print statement ==#