Extension that renders templates with Jinja
This commit is contained in:
17
examples/hello_jinja.py
Normal file
17
examples/hello_jinja.py
Normal 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()
|
||||
@@ -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__':
|
||||
|
||||
19
examples/templates/index_jinja.html
Normal file
19
examples/templates/index_jinja.html
Normal 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>
|
||||
Reference in New Issue
Block a user