klen / muffin

Muffin is a fast, simple and asyncronous web-framework for Python 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug report: render_template not part of muffin?

pyahmed opened this issue · comments

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?

@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)

You may also check this part of code in example

I see - thanks!