Skip to main content
build status coverage status

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

Release files for jinja2-sanic 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja2-sanic 0.1.2
File Size Uploaded
jinja2-sanic-0.1.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jinja2-sanic 0.1.2
File Interpreter ABI Platform
jinja2_sanic-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 12.7 kB

Release files / jinja2-sanic-0.1.2.tar.gz

Download URL jinja2-sanic-0.1.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cf8027eb1ba5cecd7bc14be944b4c56413046d03a071bbc206c385ea2fdaec15
BLAKE2b-256 checksum
How to use checksums
c7d9dc44c2388a51af3cd9b154f7b2543081e6b5ca662a19b43ec19fad52b772
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / jinja2_sanic-0.1.2-py2.py3-none-any.whl

Download URL jinja2_sanic-0.1.2-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e3ed650644ebb269be8140b500dbb56f4873750d2ec177dfcd7c3089724e1756
BLAKE2b-256 checksum
How to use checksums
c336edc55e79d1abd2f4da15595dc4ec03e4a05d34bfbca1c9c462e656060574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page