Skip to main content

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 details)

Uploaded Source

Built Distribution

fastapi_view-0.4.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_view-0.4.0.tar.gz.

File metadata

  • Download URL: fastapi_view-0.4.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.11 Darwin/23.2.0

File hashes

Hashes for fastapi_view-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ef8962f5b5bb410e1c5aa9d0f447a06074a34957d7ba6ce44ca3a9e74b22b453
MD5 22d89fb59a57a190ecb330043154048e
BLAKE2b-256 b59920711933b2a9c80405ae0d23639d5811fff78570292863abed39129b76f2

See more details on using hashes here.

File details

Details for the file fastapi_view-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_view-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.11 Darwin/23.2.0

File hashes

Hashes for fastapi_view-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9921b8c80379ac7e240a70dac054a678dfc1aca0f00f06fb258c061775183cec
MD5 6a0699ce65e9fd8ceb2772dc4274c7b1
BLAKE2b-256 e7afe8d7ebd0624154fdd39002c3a0f580be706f5dba77aae2fece58133a69a7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page