-
Core Concepts:
- FastHTML Basics: Framework for building fast, scalable web applications using pure Python. Integrates seamlessly with HTML, CSS, and JavaScript via HTMX.
- ASGI and Uvicorn: FastHTML operates on ASGI with Uvicorn as the ASGI server. Starlette provides high-level functionality on top of ASGI.
-
Routing and HTTP Methods:
- Route Definitions: Use
@rt
decorator to define routes. Function names (get
,post
,put
,delete
) map directly to HTTP methods. - Dynamic Routing: Use path parameters and types for dynamic route handling. Example:
@rt("/{fname:path}.{ext:static}")
.
- Route Definitions: Use
-
HTML and Components:
- Component Creation: Build reusable components using Python functions that return HTML elements. Example:
def hero(title, statement): return Div(H1(title), P(statement), cls="hero")
. - HTML Structure: Return HTML directly from route handlers using FastHTML's built-in functions like
Div()
,P()
,H1()
.
- Component Creation: Build reusable components using Python functions that return HTML elements. Example:
-
HTMX Integration:
- Server Interaction: Use HTMX to create dynamic server-side interactions. Any HTML element can trigger server calls via events like
hx-get
orhx-post
. - Partial Page Updates: HTMX allows returning partial HTML to update sections of the page without full reloads.
- Server Interaction: Use HTMX to create dynamic server-side interactions. Any HTML element can trigger server calls via events like
-
CSS and Styling:
- Custom Styles: Integrate CSS frameworks or custom styles using
Link
andStyle
components. Disable defaults like Pico CSS if needed. - Inline Styles: Apply inline CSS directly via the
Style()
function within components.
- Custom Styles: Integrate CSS frameworks or custom styles using
-
Advanced Features:
- Markdown Rendering: Use
MarkdownJS()
andHighlightJS()
to render Markdown and syntax-highlighted code blocks within HTML. - Static Files Handling: Serve static files (e.g., images, CSS) via custom routes with
FileResponse
.
- Markdown Rendering: Use
-
Best Practices:
- Component Reusability: Favor modular components to keep code DRY (Don't Repeat Yourself).
- HTTP Fundamentals: Leverage the full capabilities of HTTP and ASGI for performance and flexibility.
- Minimalism: Emphasize minimal and clean code, aligning with FastHTML’s lightweight design philosophy.
-
APIs and Libraries:
- Core Imports: Always start with
from fasthtml.common import *
for access to the most-used components. - CSS Frameworks: Utilize built-in CSS framework Pico.
- Core Imports: Always start with
Created
August 27, 2024 00:26
-
-
Save digitarald/704795116168d2f1eaef3b7faebe8252 to your computer and use it in GitHub Desktop.
FastHTML Copilot Instructions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment