sanic-aioja
aioja template renderer for Sanic.
This library has been inspired by so many other projects (sanic-jinja2, django-jinja). So thanks all for the inspiration.
Install
pip install sanic-aioja
Features
- Debug mode
- Babel support
@jinja2.templatedecorator- Shortcut methods:
globals,filters,tests,extensionsandpolicies - Built-in
urlandstaticglobal functions - Ability to precompile templates
Example
from sanic import Sanic
from sanic.response import html
from sanic_aioja import Jinja2, FileSystemLoader
app = Sanic("sanic_aioja")
jinja2 = Jinja2(
app,
# use DebugUndefined
debug=True,
# precompile templates on server start.
# See jinja2.Environment.compile_templates()
precompile=True,
precompile_path=".jinja2.zip",
# Jinja2 options
trim_blocks=True,
lstrip_blocks=True,
loader=FileSystemLoader("./templates"),
)
# Lets extend environment with some globals
jinja2.globals({
"token": "extensions.token",
}).policies({
"ext.i18n.trimmed": True,
})
@app.route('/')
@jinja2.template("index.html")
async def index(request):
return {
"header": "Sanic-aioja",
"array": ["Red", "Green", "Blue"],
}
@app.route('/render/')
async def index(request):
content = await jinja2.render_to_string(request, "index.html", {
"header": "Sanic-aioja",
"array": ["Red", "Green", "Blue"],
})
return html(content)
if __name__ == "__main__":
app.run()
Metadata
Release files for sanic-aioja 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sanic-aioja-0.0.1.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sanic_aioja-0.0.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 13.6 kB
Release files / sanic-aioja-0.0.1.tar.gz
| Download URL | sanic-aioja-0.0.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1803a43809dc60df8006ad1144773bacbbb9a45aa3676df4a1250ad9ff1fcf93
|
|
BLAKE2b-256 checksum How to use checksums |
70347b02e474aab32adbf76ad41bf53c8f7873ec5c2bd7781e9bd839be22ed84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / sanic_aioja-0.0.1-py2.py3-none-any.whl
| Download URL | sanic_aioja-0.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
efcac998a0d81140a1d76a04ccb57bf5315eb6f328580bcda413aaad79e1bf66
|
|
BLAKE2b-256 checksum How to use checksums |
523eb83367a9aca9d845d9f5d47cd0461829edfec622ab4bf82477b21d63c883
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|