![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
.. image:: https://github.com/aio-libs/aiohttp-jinja2/workflows/CI/badge.svg :target: https://github.com/aio-libs/aiohttp-jinja2/actions?query=workflow%3ACI .. image:: https://codecov.io/gh/aio-libs/aiohttp-jinja2/branch/master/graph/badge.svg :target: https://codecov.io/gh/aio-libs/aiohttp-jinja2 .. image:: https://img.shields.io/pypi/v/aiohttp-jinja2.svg :target: https://pypi.python.org/pypi/aiohttp-jinja2 .. image:: https://readthedocs.org/projects/aiohttp-jinja2/badge/?version=latest :target: http://aiohttp-jinja2.readthedocs.io/en/latest/?badge=latest
jinja2_ template renderer for aiohttp.web
__.
.. _jinja2: http://jinja.pocoo.org
.. _aiohttp_web: https://aiohttp.readthedocs.io/en/latest/web.html
__ aiohttp_web_
Install from PyPI::
pip install aiohttp-jinja2
Install requirement and launch tests::
pip install -r requirements-dev.txt
pytest tests
Before template rendering you have to setup jinja2 environment first:
.. code-block:: python
app = web.Application()
aiohttp_jinja2.setup(app,
loader=jinja2.FileSystemLoader('/path/to/templates/folder'))
Import:
.. code-block:: python
import aiohttp_jinja2
import jinja2
After that you may to use template engine in your web-handlers. The most convenient way is to decorate a web-handler.
Using the function based web handlers:
.. code-block:: python
@aiohttp_jinja2.template('tmpl.jinja2')
def handler(request):
return {'name': 'Andrew', 'surname': 'Svetlov'}
Or for Class Based Views <https://aiohttp.readthedocs.io/en/stable/web_quickstart.html#class-based-views>
:
.. code-block:: python
class Handler(web.View):
@aiohttp_jinja2.template('tmpl.jinja2')
async def get(self):
return {'name': 'Andrew', 'surname': 'Svetlov'}
On handler call the aiohttp_jinja2.template
decorator will pass
returned dictionary {'name': 'Andrew', 'surname': 'Svetlov'}
into
template named tmpl.jinja2
for getting resulting HTML text.
If you need more complex processing (set response headers for example)
you may call render_template
function.
Using a function based web handler:
.. code-block:: python
async def handler(request):
context = {'name': 'Andrew', 'surname': 'Svetlov'}
response = aiohttp_jinja2.render_template('tmpl.jinja2',
request,
context)
response.headers['Content-Language'] = 'ru'
return response
Or, again, a class based view:
.. code-block:: python
class Handler(web.View):
async def get(self):
context = {'name': 'Andrew', 'surname': 'Svetlov'}
response = aiohttp_jinja2.render_template('tmpl.jinja2',
self.request,
context)
response.headers['Content-Language'] = 'ru'
return response
aiohttp_jinja2
is offered under the Apache 2 license.
.. towncrier release notes start
aiohttp.web.AppKey
, and deprecate the old 'static_root_url' key.typing_extensions
on Python 3.8+.Fix type annotation for context_processors
argument #354
Bump the minimal supported aiohttp
version to 3.6.3 to avoid problems
with uncompatibility between aiohttp
and yarl
Add async rendering support #393
Remove Any from template annotations #343
Fix type annotation for filters in aiohttp_jinja2.setup
#330
Drop Python 3.5, support Python 3.9
jinja2
version to 2.10.1 to avoid security vulnerability problem.Bump minimal supported aiohttp
version to 3.2
Use request.config_dict
for accessing jinja2
environment. It
allows to reuse jinja rendering engine from parent application.
int
values in url()
jinja function to str
#191Pin to aiohttp 3.0+
Deprecate non-async handlers support
Upgrade middleware to new style from aiohttp 2.3+ #182
Autoescape all templates by default #179
Add ability to decorate class based views (available in aiohttp 0.20) #18
Upgrade aiohttp requirement to version 0.20.0+
Fix a bug in middleware (missed coroutine decorator) #16
Drop Python 3.3 support (switched to aiohttp version v0.18.0)
Simplify context processors initialization by adding parameter to setup()
Introduce context processors #14
Bypass StreamResponse #15
render_string
methodDon't allow non-mapping context
Fix tiny documentation issues
Change the library logo
render_template
functionMigrate to aiohttp 0.14
Add status
parameter to template decorator
Drop optional response
parameter
FAQs
jinja2 template renderer for aiohttp.web (http server for asyncio)
We found that aiohttp-jinja2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.