fastapi-with-tailwindcss Tailwind Templates

Fastapi With Tailwindcss

tailwind for fastapi tailwindcss without nodejs

FastAPI + TailwindCSS

Getting Started

Installation

virtualenv

python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
pip install -r requirements.txt

FastAPI

pip install fastapi

Uvicorn

pip install uvicorn

FastAPI-TailwindCSS Lib refer.

tailwind config

Make sure the static folder exists.

mkdir ./static

Get output.css (test)

python main.py dev

Generate tailwind.config.js, then configure it appropriately. refer.

tailwind.config.js path: root & html in same path

module.exports = {
  content: ["*.html"],
  theme: {
    extend: {},
  },
  plugins: [],
}

tailwind.config.js path: ./tailwindcss & html in templates

module.exports = {
  content: "../templates/**/*.html"],
  theme: {
    extend: {},
  },
  plugins: [],
}

Get appyled tailwind css in app

python main.py dev

Refer.

lifespan -> npx tailwindcss -i ./styles/app.css -o ../static/output.css --watch

@asynccontextmanager
async def lifespan(app: FastAPI):
    process = tailwind.compile(static_files.directory + "/output.css")

    yield

    process.terminate()

app = FastAPI(
    lifespan=lifespan
)

Top categories

Loading Svelte Themes