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() 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.2.0.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_view-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a64de74ba7927afd0a3150dd1c7b261d55b0b76f246c3d6d4abd2fdb33f53978 |
|
MD5 | fb5b4a7cf08bce62fd2ab1fbb9c467d4 |
|
BLAKE2b-256 | 8ab6fb2f44ac7293bd05366c3e7113052bbb139c9245114d260d71c3d966792b |