Open
Description
Sometimes it's nice to use FastUI's python integration with local copies of the js/css files:
- Situations where there is no Internet/CDN connectivity, such as behind a corporate firewall (See It works only with internet #307)
- When using/testing custom builds of the TypeScript components
Instructions might look something like:
Using Local Copies of the JS/CSS files:
- download the js and css files locally (ensure you have the correct version numbers, since these links are just examples):
- https://cdn.jsdelivr.net/npm/@pydantic/[email protected]/dist/assets/index.js
- https://cdn.jsdelivr.net/npm/@pydantic/[email protected]/dist/assets/index.css
-
Place
index.js
andindex.css
in a folder under your fastapi/flask project where you serve static files, for example inside astatic/assets
folder. -
Configure fastapi and fastui as something like the following. Note that the key is to set the
fastui._PREBUILT_CDN_URL
variable that fastui uses for defining the location of the JS/CSS files, when generating the HTML pages.
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
import fastui
app = FastAPI()
# make sure you have a folder named 'static' in your project and put the css and js files inside a subfolder called 'assets'
app.mount("/static", StaticFiles(directory="static"), name="static")
# configure fastui to use these local css and js files instead of the ones on the CDN
fastui._PREBUILT_CDN_URL = f'/static/assets'
...
Metadata
Metadata
Assignees
Labels
No labels