Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yunstanford/jinja2-sanic
a jinja2 template renderer for Sanic
https://github.com/yunstanford/jinja2-sanic
async jinja2 python3 sanic
Last synced: 2 months ago
JSON representation
a jinja2 template renderer for Sanic
- Host: GitHub
- URL: https://github.com/yunstanford/jinja2-sanic
- Owner: yunstanford
- License: apache-2.0
- Archived: true
- Created: 2017-07-20T17:50:59.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-31T13:00:09.000Z (over 4 years ago)
- Last Synced: 2024-10-12T06:26:11.598Z (3 months ago)
- Topics: async, jinja2, python3, sanic
- Language: Python
- Homepage: http://jinja2-sanic.readthedocs.io/en/latest/
- Size: 28.3 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-sanic - Jinja2-sanic
README
jinja2-sanic
============.. image:: https://travis-ci.org/yunstanford/jinja2-sanic.svg?branch=master
:alt: build status
:target: https://travis-ci.org/yunstanford/jinja2-sanic.. image:: https://coveralls.io/repos/github/yunstanford/jinja2-sanic/badge.svg?branch=master
:alt: coverage status
:target: https://coveralls.io/github/yunstanford/jinja2-sanic?branch=mastera jinja2 template renderer for Sanic. It supports:
* function based web handlers
* class-based views
* decoractors for convenient useageYou can find out more here:
http://jinja2-sanic.readthedocs.io/en/latest/
This lib has been strongly influenced by `aiohttp-jinja2 `_.
-------
Install
-------.. code::
pip3 install jinja2-sanic
-----------
Quick Start
-----------.. code-block:: python
from sanic import Sanic
from sanic.views import HTTPMethodView
from sanic.exceptions import ServerErrorapp = Sanic("sanic_jinja2_render")
# Setup jinja2 environment
template = "{{Player}}
{{Category}}"
jinja2_sanic.setup(
app,
loader=jinja2.DictLoader(
{
"templates.jinja2": template
}
)
)# Usage in function based web handlers
@app.route("/")
@jinja2_sanic.template("templates.jinja2")
async def func(request):
return {
"Player": "CR7",
"Category": "Soccer",
}# Usage in class-based views
class SimpleView(HTTPMethodView):@jinja2_sanic.template("templates.jinja2")
async def get(self, request):
return {
"Player": "CR7",
"Category": "Soccer",
}# register class based view routes
app.add_route(SimpleView.as_view(), "/")# Start Server
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)-----------
Development
-----------``jinja2-sanic`` accepts contributions on GitHub, in the form of issues or pull requests.
Build.
.. code::
./uranium
Run unit tests.
.. code::
./uranium test