Bug report: render_template not part of muffin?
pyahmed opened this issue · comments
pyahmed commented
Describe the bug
https://klen.github.io/muffin/usage.html#the-request-object has the following code
@app.route('/login', methods=['POST', 'PUT'])
async def login(request):
error = None
if request.method == 'POST':
formdata = await request.form()
if valid_login(formdata['username'], formdata['password']):
return log_the_user_in(formdata['username'])
error = 'Invalid username/password'
return render_template('login.html', error=error)
From where exactly can you can import render_template()? Or is it not part of muffin?
Kirill Klenov commented
@pyahmed Hello, this is an abstract example, but the Muffin has Muffin-Jinja2 plugin to render Jinja2 templates.
from muffin_jinja2 import Plugin as Jinja2
# Initialize the jinja plugin somewhere
jinja = Jinja2(app)
@app.route('/login', methods=['POST', 'PUT'])
async def login(request):
error = None
if request.method == 'POST':
formdata = await request.form()
if valid_login(formdata['username'], formdata['password']):
return log_the_user_in(formdata['username'])
error = 'Invalid username/password'
return await jinja2.render('login.html', error=error)
pyahmed commented
I see - thanks!