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
-
Jinja2 templates directory setup.
import os from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from fastapi_view import view from fastapi_view.middleware import ViewRequestMiddleware @asynccontextmanager async def lifespan(app: FastAPI): view.initialize(Jinja2Templates(directory="./assets/views"), use_vite=True) yield app = FastAPI(title="Test app", lifespan=lifespan)
-
Use
view()
to render Jinja2 *.html files.@app.get("/") def index(): # index.html in ./assets/views return view("index", {"foo": "bar"})
-
Use
inertia.render()
to render *.vue files.from fastapi_view import inertia @app.get("/inertia/page") def inertia_index(): # Index.vue in ./assets/js/Pages/views return inertia.render("Index", props={"foo": "bar"})
-
Find more examples in example directory.
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.4.0.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_view-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9921b8c80379ac7e240a70dac054a678dfc1aca0f00f06fb258c061775183cec |
|
MD5 | 6a0699ce65e9fd8ceb2772dc4274c7b1 |
|
BLAKE2b-256 | e7afe8d7ebd0624154fdd39002c3a0f580be706f5dba77aae2fece58133a69a7 |