- Add return type annotations and parameter types - Import necessary typing modules (Optional, Union, Flask, Response) - Improve code readability and IDE support for examples - All existing tests continue to pass
19 lines
480 B
Python
19 lines
480 B
Python
from flask import jsonify
|
|
from flask import render_template
|
|
from flask import request
|
|
from flask import Response
|
|
|
|
from . import app
|
|
|
|
|
|
@app.route("/", defaults={"js": "fetch"})
|
|
@app.route("/<any(xhr, jquery, fetch):js>")
|
|
def index(js: str) -> str:
|
|
return render_template(f"{js}.html", js=js)
|
|
|
|
|
|
@app.route("/add", methods=["POST"])
|
|
def add() -> Response:
|
|
a = request.form.get("a", 0, type=float)
|
|
b = request.form.get("b", 0, type=float)
|
|
return jsonify(result=a + b)
|