-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
73 lines (56 loc) · 1.67 KB
/
run.py
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
import json
import os
import click
from flask import Flask, render_template, request
from werkzeug.exceptions import abort
from middleware import middleware
app = Flask(__name__)
### Basic Middleware Method ##
app.wsgi_app = middleware(app.wsgi_app)
### injected Middleware functions ###
def before_req_func():
print(f"sparked before request procession")
def after_req_func(res):
print(f"sparked after request procession")
print(res.content_type, res.response)
return res
app.before_request_funcs = {
None: [before_req_func]
}
app.after_request_funcs = {
None: [after_req_func]
}
### Routes To HTML Views ###
@app.cli.command('hello')
@click.argument('name')
def hello(name):
res = f"Hello {name}"
print(res)
@app.route('/', methods=['GET'])
def index():
return render_template('index_form.html')
@app.route('/', methods=['POST'])
def index_post():
values = request.form
return render_template('index.html', form_data=values)
@app.route('/app')
def to_app():
zeuch = ['dies','kommt','aus','einer','liste']
return render_template('app.html', zeuch=zeuch)
@app.route('/<int:num>')
def num(num):
if num not in range(10):
### simple 404 example
abort(404)
return render_template('num.html', num=num)
### Routes To Json Views ###
@app.route('/hello/<string:name>')
def hello_name(name):
return json.dumps({"hello": name})
### Import Debugger if needed ###
if os.getenv("PYTHONDEBUGGER") == "True":
import multiprocessing
if multiprocessing.current_process().pid > 1:
import debugpy
debugpy.listen(("0.0.0.0", 3000))
print("⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳")