Não reinvente a roda
É má prática, mocinho!
from flask import Flask, request
from jinja2 import Environment, PackageLoader, select_autoescape
= Environment(
env =PackageLoader("app"),
loader=select_autoescape(),
autoescape
)
= Flask("testapp")
app
# Make a dry run to create a custom template for logs. Outputs a
# example of the rendered template.
@app.route("/logs/templates/dry", methods=["POST"])
def root():
= request.json
request_data = env.from_string(
template "content"],
request_data[globals=request_data["global_variables"],
)
return template.render(
{"app": {
"name": "Test APP",
"url": "https://test-app.example.com",
"port": 443,
"https_enabled": True,
},"errors": [
{"message": "Something went wrong!",
"stacktrace": [
"...",
],
},
],
} )