Comments (5)
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.
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.
Yes, code example would be useful.
from aiohttp-mako.
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.
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)
- Deprecated from collections import Mapping HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Release 0.0.1 HOT 2
- Archive this project?
- Let's put `aiohttp-mako` under the `aio-libs` org on PyPI
- Add an option for including the request into the template context, similar to what Pyramid does. HOT 1
- Yum broken when RPM from this requirement with underscores. HOT 1
- Drop python 3.4 support and fix minimal version python3.5.3 HOT 1
- Update all `secret: ` values in `.travis.yml` HOT 1
- How setup template directory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp-mako.