Extension that renders templates with Jinja

This commit is contained in:
Miguel Grinberg
2022-07-29 20:19:51 +01:00
parent 7df74b0537
commit 7686b2ae38
11 changed files with 123 additions and 11 deletions

17
examples/hello_jinja.py Normal file
View File

@@ -0,0 +1,17 @@
from microdot import Microdot, Response
from microdot_jinja import render_template
app = Microdot()
Response.default_content_type = 'text/html'
@app.route('/', methods=['GET', 'POST'])
def index(req):
name = None
if req.method == 'POST':
name = req.form.get('name')
return render_template('index_jinja.html', name=name)
if __name__ == '__main__':
app.run()

View File

@@ -10,7 +10,7 @@ def index(req):
name = None
if req.method == 'POST':
name = req.form.get('name')
return render_template('index.html', name=name)
return render_template('index_utemplate.html', name=name)
if __name__ == '__main__':

View File

@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<title>Microdot + Jinja example</title>
</head>
<body>
<h1>Microdot + Jinja example</h1>
{% if name %}
<p>Hello, <b>{{ name }}</b>!</p>
{% endif %}
<form method="POST">
<p>
What is your name?
<input type="text" name="name" autofocus />
</p>
<input type="submit" value="Submit" />
</form>
</body>
</html>