No project description provided
Project description
a jinja2 template renderer for Sanic. It supports:
function based web handlers
class-based views
decoractors for convenient useage
You can find out more here:
http://jinja2-sanic.readthedocs.io/en/latest/
Install
pip3 install jinja2-sanic
Quick Start
from sanic import Sanic
from sanic.views import HTTPMethodView
from sanic.exceptions import ServerError
app = Sanic("sanic_jinja2_render")
# Setup jinja2 environment
template = "<html><body><h1>{{Player}}</h1>{{Category}}</body></html>"
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.
./uranium
Run unit tests.
./uranium test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jinja2-sanic-0.1.2.tar.gz.
File metadata
- Download URL: jinja2-sanic-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf8027eb1ba5cecd7bc14be944b4c56413046d03a071bbc206c385ea2fdaec15
|
|
| MD5 |
b2e427ee103d520dc0f8f7809d9d155a
|
|
| BLAKE2b-256 |
c7d9dc44c2388a51af3cd9b154f7b2543081e6b5ca662a19b43ec19fad52b772
|
File details
Details for the file jinja2_sanic-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: jinja2_sanic-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3ed650644ebb269be8140b500dbb56f4873750d2ec177dfcd7c3089724e1756
|
|
| MD5 |
33325d914b881a641787aac81c00b3ca
|
|
| BLAKE2b-256 |
c336edc55e79d1abd2f4da15595dc4ec03e4a05d34bfbca1c9c462e656060574
|