Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Flask (Python)

flask official docs

installation

flask --app scriptfile.py run

from flask import Flask, render_template, jsonify

app = Flask(__name__)

@app.route('/hello/<path:subpath>', methods=['GET', 'POST'])
def hello_world(subpath):
    return f"<p>Hello, World! {subpath}</p>"
    
@app.route('/template/')
@app.route('/template/<name>')
def hello(name=None):
    request_data = request.get_json(silent=True)
    return render_template('hello.html', person=name)

@app.rout('/json')
def json():
    dict = {"a": 0}
    return jsonify(dict)