Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.08 KB

README.md

File metadata and controls

56 lines (40 loc) · 1.08 KB

Jinja for Naja Atra

This is a Jinja extension for Naja Atra

Installation

python3 -m pip install naja_atra_jinja

Usage

from naja_atra import route, server
from naja_atra_jinja import JinjaView

@route("/index")
def index(name: str = "world"):
    return JinjaView("index.html", {"name": name})

def main():
    server.start(port=9090)

if __name__ == "__main__":
    main()

For the above code, the templates should be placed in the templates folder in your project's root.

|--templates
|----index.html
|----page.html
|--main.py

You can set your own Jinja2 Environment via set_env function:

from naja_atra import route, server
from naja_atra_jinja import JinjaView, set_env
from jinja2 import Environment, FileSystemLoader

@route("/index")
def index(name: str = "world"):
    return JinjaView("index.html", {"name": name})

def main():
    env = Environment(loader=FileSystemLoader("/you/own/template/folder"))
    set_env(env)
    server.start(port=9090)

if __name__ == "__main__":
    main()