ESD Lab 1 + 2 Quiz
11 Questions
5 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

The app.route(...) used to define service routes is a decorator in python.

  • True (correct)
  • False
  • NA
  • NA
  • Which statement is NOT correct about the code below, based on our labs?

    if name == 'main': app.run(port=5000, debug=True)

  • The flask program uses port 5000 when app.run runs.
  • __name__ is a special variable, indicating the name of the current python module; it is set to '__main__' when the module is read from the standard input, a script, or from an interactive prompt, but not when imported from another module.
  • Because of 'debug=True', we need to manually restart the app (Ctrl+C and rerun the python module) whenever the code is changed while it is running. (correct)
  • The app.run will not run when the python file is imported by another python program.
  • In the lab code, app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root@localhost:3306/book' specifies a book database. Now let's assume the database is relocated on a server with the IP address 10.0.40.3. Which part of the URI do you need to replace with 10.0.40.3?

  • mysqlconnector
  • root@localhost
  • root@localhost:3306
  • localhost (correct)
  • from flask import Flask, request, jsonify from flask_sqlalchemy import SQLAlchemy

    app = Flask(name) app.config['SQLALCHEMY_DATABASE_URI'] =
    'mysql+mysqlconnector://jason:mary@localhost:3306/asset' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app)

    class Asset(db.Model): tablename = 'asset'

    asset_num = db.Column(db.String(32), primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    description = db.Column(db.String(256), nullable=False)
    owner_id = db.Column(db.Integer)
    
    def __init__(self, asset_num, name, description, owner_id):
        self.asset_num = asset_num
        self.name = name
        self.description = description
        self.owner_id = owner_id
    

    more codes below...

    <p>A, B, C</p> Signup and view all the answers

    WampServer is also a web service.

    <p>False</p> Signup and view all the answers

    The parameter used for app.route(...) should contain a complete URL including either a hostname or an IP, such as "http://127.0.0.1:5000/" or "http://127.0.0.1:5000/book/".

    <p>False</p> Signup and view all the answers

    @app.route("/book/title/") def find_by_title(title):
    book = db.session.scalars( db.select(Book).filter_by(title=title). limit(1) ).first() if book: return jsonify( { "code": 216, "data": "yes" } ) return jsonify( { "code": 404, "message": "Dun tell you." } ), 444

    <p>A &amp; B</p> Signup and view all the answers

    The Flask-SQLAlchemy python package is a service.

    <p>False</p> Signup and view all the answers

    The postman app is a service consumer.

    <p>True</p> Signup and view all the answers

    The book.py implements a REST web service.

    <p>True</p> Signup and view all the answers

    from flask import Flask app = Flask(name)

    @app.route("/") def www(): return "HELLO"

    def home(): return "HI"

    python -m flask run

    <p>Open URL <a href="http://127.0.0.1:5000/">http://127.0.0.1:5000/</a> in the browser will display &quot;HELLO&quot;.</p> Signup and view all the answers

    Use Quizgecko on...
    Browser
    Browser