GithubHelp home page GithubHelp logo

dldevinc / sanic-aioja Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 26 KB

aioja template renderer for Sanic

License: BSD 3-Clause "New" or "Revised" License

Python 89.10% HTML 10.90%
sanic jinja2 async

sanic-aioja's Introduction

sanic-aioja

aioja template renderer for Sanic.

This library has been inspired by so many other projects such as sanic-jinja2 and django-jinja.

PyPI Build Status

Install

pip install sanic-aioja

Features

  • Debug mode
  • Babel support
  • @jinja2.template decorator
  • Shortcut methods: globals, filters, tests, extensions and policies
  • Built-in url and static global 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"),    
)

# Let's 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()

sanic-aioja's People

Watchers

James Cloos avatar Mihail avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.