Podcast
Questions and Answers
The app.route(...) used to define service routes is a decorator in python.
The app.route(...) used to define service routes is a decorator in python.
Which statement is NOT correct about the code below, based on our labs?
if name == 'main':
app.run(port=5000, debug=True)
Which statement is NOT correct about the code below, based on our labs?
if name == 'main': app.run(port=5000, debug=True)
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?
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?
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...
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...
Signup and view all the answers
WampServer is also a web service.
WampServer is also a web service.
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/".
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/".
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
@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
Signup and view all the answers
The Flask-SQLAlchemy python package is a service.
The Flask-SQLAlchemy python package is a service.
Signup and view all the answers
The postman app is a service consumer.
The postman app is a service consumer.
Signup and view all the answers
The book.py implements a REST web service.
The book.py implements a REST web service.
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
from flask import Flask app = Flask(name)
@app.route("/") def www(): return "HELLO"
def home(): return "HI"
python -m flask run
Signup and view all the answers