fastapi-view


Namefastapi-view JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/turisesonia/fastapi-view.git
SummaryA jinja2 view template helping function for FastAPI.
upload_time2024-10-01 07:30:57
maintainerNone
docs_urlNone
authorSam Yao
requires_python<4.0,>=3.10
licenseMIT
keywords fastapi template view jinja2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fastapi-view

A jinja2 view template helping function for FastAPI.

Features:

- Simply setting and use function to return Jinja2Templates

### Installation

```shell
pip install fastapi-view
```

### Usage

- Jinja2 templates directory setup.

  ```python
  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.

  ```python
  @app.get("/")
  def index():
      # index.html in ./assets/views
      return view("index", {"foo": "bar"})
  ```

- Use `inertia.render()` to render *.vue files.

  ```python
  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](./example) directory.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/turisesonia/fastapi-view.git",
    "name": "fastapi-view",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "Fastapi, template, view, jinja2",
    "author": "Sam Yao",
    "author_email": "turisesonia@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b5/99/20711933b2a9c80405ae0d23639d5811fff78570292863abed39129b76f2/fastapi_view-0.4.0.tar.gz",
    "platform": null,
    "description": "# fastapi-view\n\nA jinja2 view template helping function for FastAPI.\n\nFeatures:\n\n- Simply setting and use function to return Jinja2Templates\n\n### Installation\n\n```shell\npip install fastapi-view\n```\n\n### Usage\n\n- Jinja2 templates directory setup.\n\n  ```python\n  import os\n  from contextlib import asynccontextmanager\n\n  from fastapi import FastAPI\n  from fastapi.staticfiles import StaticFiles\n  from fastapi.templating import Jinja2Templates\n\n  from fastapi_view import view\n  from fastapi_view.middleware import ViewRequestMiddleware\n\n  @asynccontextmanager\n  async def lifespan(app: FastAPI):\n      view.initialize(Jinja2Templates(directory=\"./assets/views\"), use_vite=True)\n      yield\n\n  app = FastAPI(title=\"Test app\", lifespan=lifespan)\n  ```\n\n- Use `view()` to render Jinja2 *.html files.\n\n  ```python\n  @app.get(\"/\")\n  def index():\n      # index.html in ./assets/views\n      return view(\"index\", {\"foo\": \"bar\"})\n  ```\n\n- Use `inertia.render()` to render *.vue files.\n\n  ```python\n  from fastapi_view import inertia\n\n  @app.get(\"/inertia/page\")\n  def inertia_index():\n      # Index.vue in ./assets/js/Pages/views\n      return inertia.render(\"Index\", props={\"foo\": \"bar\"})\n  ```\n\n- Find more examples in [example](./example) directory.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A jinja2 view template helping function for FastAPI.",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/turisesonia/fastapi-view.git",
        "Repository": "https://github.com/turisesonia/fastapi-view.git"
    },
    "split_keywords": [
        "fastapi",
        " template",
        " view",
        " jinja2"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7afe8d7ebd0624154fdd39002c3a0f580be706f5dba77aae2fece58133a69a7",
                "md5": "6a0699ce65e9fd8ceb2772dc4274c7b1",
                "sha256": "9921b8c80379ac7e240a70dac054a678dfc1aca0f00f06fb258c061775183cec"
            },
            "downloads": -1,
            "filename": "fastapi_view-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a0699ce65e9fd8ceb2772dc4274c7b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 6405,
            "upload_time": "2024-10-01T07:30:55",
            "upload_time_iso_8601": "2024-10-01T07:30:55.884674Z",
            "url": "https://files.pythonhosted.org/packages/e7/af/e8d7ebd0624154fdd39002c3a0f580be706f5dba77aae2fece58133a69a7/fastapi_view-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b59920711933b2a9c80405ae0d23639d5811fff78570292863abed39129b76f2",
                "md5": "22d89fb59a57a190ecb330043154048e",
                "sha256": "ef8962f5b5bb410e1c5aa9d0f447a06074a34957d7ba6ce44ca3a9e74b22b453"
            },
            "downloads": -1,
            "filename": "fastapi_view-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "22d89fb59a57a190ecb330043154048e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5136,
            "upload_time": "2024-10-01T07:30:57",
            "upload_time_iso_8601": "2024-10-01T07:30:57.457713Z",
            "url": "https://files.pythonhosted.org/packages/b5/99/20711933b2a9c80405ae0d23639d5811fff78570292863abed39129b76f2/fastapi_view-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-01 07:30:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "turisesonia",
    "github_project": "fastapi-view",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "fastapi-view"
}
        
Elapsed time: 0.33754s