A jinja2 view template helping function for FastAPI.
Project description
fastapi-view
A jinja2 view template helping function for FastAPI.
Features:
- Simply setting and use function to return Jinja2Templates
Installation
pip install fastapi-view
Usage
-
Configuring
fastapi-view
jinja2 templates directory pathfrom fastapi_view import view # setting root view templates directory path view.views_directory = "/your/jinja2/template/directory/path"
-
Use view()
from fastapi import FastAPI from fastapi.requests import Request from fastapi_view.middleware import ViewRequestMiddleware from fastapi_view import view app = FastAPI() from fastapi_view.middleware import ViewRequestMiddleware app.add_middleware(ViewRequestMiddleware) @app.get("/") def index(): return view("index", {"foo": "bar"})
-
Use inertia render
from fastapi import FastAPI from fastapi.requests import Request from fastapi_view.middleware import ViewRequestMiddleware from fastapi_view import inertia app = FastAPI() app.add_middleware(ViewRequestMiddleware) @app.get("/inertia/page") def inertia_index(): return inertia.render("Index", props={"foo": "bar"})
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi-view-0.1.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_view-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81982d2d5dc5fc043bc0390487f62b926a49fcaef6000a640fb54fc0bfa2b677 |
|
MD5 | c636911f481da6001ae1b39ebc2ec130 |
|
BLAKE2b-256 | 3ec2d8b012e68f91c39c62cc099031b261f521d2108a7710114c583fc5d0bfe1 |