Giter Club home page Giter Club logo

Comments (5)

asvetlov avatar asvetlov commented on May 24, 2024

What's your use case?

aiohttp_mako.template decorator supposed to be used with aiohttp web-handlers only.
web-handler accepts the only request parameter -- that's how aiohttp.web works.
If you really need something non-standard please invite your own decorator which uses render_template function internally.

from aiohttp-mako.

neRok00 avatar neRok00 commented on May 24, 2024

I doubt I am doing it right, but I was attempting to return the get function for a route after an unsuccessful post, and pass some messages etc in the process. I suppose I should be attaching them to the request session first, or something similar.

from aiohttp-mako.

asvetlov avatar asvetlov commented on May 24, 2024

Yes, code example would be useful.

from aiohttp-mako.

neRok00 avatar neRok00 commented on May 24, 2024

Here is a simplified example of a login route that accepts GET and POST.

import asyncio
from aiohttp.web import HTTPFound
import aiohttp_mako

@asyncio.coroutine
@aiohttp_mako.template('login.html')
def get(request, message=None):
    return {'message': message}

@asyncio.coroutine
def post(request):
    post = yield from request.post()
    try:
        # Get the user and validate the password, raise Exception if not correct.
    except Exception:
        message = 'The supplied username and password were not correct.'
        response = yield from get(request, message=message)
        return reponse
    # Add the user to the session etc, and return to home page.
    return HTTPFound(request.app.router['home'].url())

Just thinking about your comment "web-handler accepts the only request parameter". If this is the case, why is the wrapped function using *args?

def wrapped(*args):
    #<snip>
    context = yield from coro(*args)
    request = args[-1]

Would the following be more appropriate?

def wrapped(request):
    #<snip>
    context = yield from coro(request)

from aiohttp-mako.

asvetlov avatar asvetlov commented on May 24, 2024

The only reason for accepting *args: web-handler shaped as method should have a different signature: it accepts (self, request).

from aiohttp-mako.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.