Render templates with uTemplate
This commit is contained in:
17
examples/hello_utemplate.py
Normal file
17
examples/hello_utemplate.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from microdot import Microdot, Response
|
||||
from microdot_utemplate 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.html', name=name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
17
examples/hello_utemplate_async.py
Normal file
17
examples/hello_utemplate_async.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from microdot_asyncio import Microdot, Response
|
||||
from microdot_utemplate import render_template
|
||||
|
||||
app = Microdot()
|
||||
Response.default_content_type = 'text/html'
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
async def index(req):
|
||||
name = None
|
||||
if req.method == 'POST':
|
||||
name = req.form.get('name')
|
||||
return render_template('index.html', name=name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
20
examples/templates/index.html
Normal file
20
examples/templates/index.html
Normal file
@@ -0,0 +1,20 @@
|
||||
{% args name %}
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Microdot + uTemplate example</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Microdot + uTemplate 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