It contains:
url_for
- flask-like url reverserjsonify
- flask-like json-dumper with support ofdatetime
, andObjectId
redirect
- django-like redirectget_argument
- tornado-like util to get GET / POST argumentsstatic_url
- tornado-like url-wrapper to add version hast to static assetflash
- simple flash messages, usage described bellowget_client_ip
- client IP addressfix_host
- middleware for redirect requests by IP to right domaintemplate_handler
- handler that just render templateurl_for_processor
- context processor for usingurl_for
without passing requestsession_processor
- context_processor foraiohttp_session
Look at the example folder for working example.
pip install aiohttp_tools
Repository: https://github.com/imbolc/aiohttp_tools
from aiohttp_tools.flash import flash
# you should include session middleware before flash middleware
aiohttp_session.setup(app, ...)
app.middlewares.append(aiohttp_tools.flash.middleware)
context_processors.append(aiohttp_tools.flash.context_processor)
async def handler(request):
flash.message(request, 'Message', 'level')
# shortcuts
flash.info(request, 'Some message')
flash.success(...)
flash.warning(...)
flash.error(...)
{% for message, level in get_flashed_messages() %}
<div class="flash {{ level }}">
{{ message }}
</div>
{% endfor %}