-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (54 loc) · 1.63 KB
/
main.py
File metadata and controls
76 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from os import getenv
from flask import Flask, request, render_template
from flask_migrate import Migrate
from models import db
from views.products import products_app
app = Flask(__name__)
CONFIG_OBJECT = getenv("CONFIG", "DevelopmentConfig")
app.config.from_object(f"config.{CONFIG_OBJECT}")
db.app = app
db.init_app(app)
migrate = Migrate(app, db, compare_type=True)
app.register_blueprint(products_app, url_prefix="/products")
# with app.app_context():
# db.create_all()
# db.create_all()
# db.drop_all()
@app.route("/", endpoint="index_page")
def hello_world():
print_request()
# return "<h1>Hello, World!</h1>"
return render_template("index.html")
# return render_template("base.html")
def print_request():
print("request:", request)
print("request.method", request.method)
print("request.path", request.path)
@app.route("/hello/")
@app.route("/hello/<name>/")
def hello_view(name: str = None):
print_request()
if name is None:
name = request.args.get("name", "")
name = name.strip()
if not name:
name = "World"
# names = request.args.getlist("name")
# print(request.args)
# return {"message": "Hello!", "name": name, "names": names}
return {"message": f"Hello {name}!"}
@app.route("/items/<int:item_id>/")
def get_item(item_id: int):
return {
"item": {"id": item_id},
}
@app.route("/items/<item_id>/")
def get_item_string(item_id: str):
return {
"item_id": item_id.upper(),
}
# @app.route("/hello/<name>/")
# def hello_name(name: str):
# return {"message": f"Hello {name}!"}
if __name__ == "__main__":
app.run(debug=True)