Name | hotmix JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | Add htmx to your FastAPI application |
upload_time | 2024-09-18 16:30:15 |
maintainer | None |
docs_url | None |
author | flokapi |
requires_python | <4.0,>=3.7 |
license | LGPL-3.0-only |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# About
HotMix allows you to conveniently add htmx to your FastAPI app.
# Getting Started
Install the packages
```
pip install uvicorn fastapi jinja2 hotmix
```
Create a tempate folder and add a template.
```
main.py
templates/
index.html
```
Content of `index.html`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simple Page</title>
</head>
<body>
<h1>HotMix Hello World</h1>
<p>Parameter from the API: {{ param }}</p>
<p>You are accessing the path: {{ request.url.path }}</p>
</body>
</html>
```
Content of `main.py`
```python
from fastapi import FastAPI, Request
import hotmix as hm
app = FastAPI()
hm.init("templates")
@app.get("/")
@hm.htmx("index")
async def main(request: Request):
return {"param": 37}
```
# How it works
Initialize hotmix while setting the templates folder path
```python
import hotmix as hm
hm.init("templates")
```
For each of the routes which should return some htmx content, add a decorator specifying the name of the template file, without the `.html` extension.
```python
@app.get("/")
@hm.htmx("index")
async def main(request: Request):
return {"param": 37}
```
Instead of returning the dictionary as JSON data, it will pass the dictionary to the jinja2 template engine, which will return the `.html` with the desired parameters.
HotMix can handle two kinds of parameters:
- Explicit paramters: returned in the request answer dictionary. They are accessed by giving their names: `{{ param }}`.
- Request parameters, accessed through the `request` keyword. For example `{{ request.url.path }}`.
Raw data
{
"_id": null,
"home_page": null,
"name": "hotmix",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.7",
"maintainer_email": null,
"keywords": null,
"author": "flokapi",
"author_email": "flokapi@pm.me",
"download_url": "https://files.pythonhosted.org/packages/f0/bd/eff0f0007906e736fce043a695f517606485802727d0382f93b12ca949b3/hotmix-0.0.4.tar.gz",
"platform": null,
"description": "# About\n\nHotMix allows you to conveniently add htmx to your FastAPI app.\n\n# Getting Started\n\nInstall the packages\n\n```\npip install uvicorn fastapi jinja2 hotmix\n```\n\nCreate a tempate folder and add a template.\n\n```\nmain.py\ntemplates/\n\tindex.html\n```\n\nContent of `index.html`\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Simple Page</title>\n </head>\n <body>\n <h1>HotMix Hello World</h1>\n <p>Parameter from the API: {{ param }}</p>\n <p>You are accessing the path: {{ request.url.path }}</p>\n </body>\n</html>\n```\n\nContent of `main.py`\n\n```python\nfrom fastapi import FastAPI, Request\nimport hotmix as hm\n\napp = FastAPI()\nhm.init(\"templates\")\n\n@app.get(\"/\")\n@hm.htmx(\"index\")\nasync def main(request: Request):\n return {\"param\": 37}\n```\n\n\n\n# How it works\n\nInitialize hotmix while setting the templates folder path\n\n```python\nimport hotmix as hm\n\nhm.init(\"templates\")\n```\n\nFor each of the routes which should return some htmx content, add a decorator specifying the name of the template file, without the `.html` extension.\n\n```python\n@app.get(\"/\")\n@hm.htmx(\"index\")\nasync def main(request: Request):\n return {\"param\": 37}\n```\n\nInstead of returning the dictionary as JSON data, it will pass the dictionary to the jinja2 template engine, which will return the `.html` with the desired parameters.\n\nHotMix can handle two kinds of parameters:\n\n- Explicit paramters: returned in the request answer dictionary. They are accessed by giving their names: `{{ param }}`.\n- Request parameters, accessed through the `request` keyword. For example `{{ request.url.path }}`.\n\n",
"bugtrack_url": null,
"license": "LGPL-3.0-only",
"summary": "Add htmx to your FastAPI application",
"version": "0.0.4",
"project_urls": {
"documentation": "https://github.com/flokapi/hotmix",
"homepage": "https://github.com/flokapi/hotmix",
"repository": "https://github.com/flokapi/hotmix"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1deb55911d955014f0f7cd86476d82d9c0983aa05902e100a788416a90672572",
"md5": "2b144c4a8030d6f19860956979f0b3c4",
"sha256": "ce92d24d671a68495efabfe14bb4f10465cd0c5debcfd89a5dc52376dfc838cb"
},
"downloads": -1,
"filename": "hotmix-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2b144c4a8030d6f19860956979f0b3c4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.7",
"size": 2781,
"upload_time": "2024-09-18T16:30:13",
"upload_time_iso_8601": "2024-09-18T16:30:13.898046Z",
"url": "https://files.pythonhosted.org/packages/1d/eb/55911d955014f0f7cd86476d82d9c0983aa05902e100a788416a90672572/hotmix-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f0bdeff0f0007906e736fce043a695f517606485802727d0382f93b12ca949b3",
"md5": "c4a39a0f39dc7d03d5da01db4292e274",
"sha256": "3683a5fb090c7858b4ba5f95913228317c1a0ce3038151fb19f6c6e24031f574"
},
"downloads": -1,
"filename": "hotmix-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "c4a39a0f39dc7d03d5da01db4292e274",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.7",
"size": 2248,
"upload_time": "2024-09-18T16:30:15",
"upload_time_iso_8601": "2024-09-18T16:30:15.449640Z",
"url": "https://files.pythonhosted.org/packages/f0/bd/eff0f0007906e736fce043a695f517606485802727d0382f93b12ca949b3/hotmix-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-18 16:30:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "flokapi",
"github_project": "hotmix",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "hotmix"
}