Django compatibility #434
Replies: 1 comment
-
ANSWER: Prefab (PrefectHQ) + Django CompatibilityDiscussion: #434 SHORT ANSWERYes, Prefab is compatible with Django, but not as a directly installable WHAT PREFAB IS (context)Prefab is a Python UI framework that compiles component trees to JSON, HOW TO USE PREFAB WITH DJANGOOPTION 1 — Run as separate services (simplest approach)Run Prefab on a different port alongside Django. They coexist without Terminal 1 - Djangopython manage.py runserver 8000 Terminal 2 - Prefabprefab serve my_ui.py --port 8001 In your Prefab UI, use HTTP actions to call your Django API endpoints: from prefab_ui.components import Button Button("Load Data", on_click=FetchData("http://localhost:8000/api/data/")) This is the recommended approach for most use cases. OPTION 2 — Serve Prefab JSON from a Django viewPrefab compiles to plain JSON. You can generate that JSON inside a Django views.pyfrom django.http import JsonResponse def dashboard_view(request): urls.pyfrom django.urls import path urlpatterns = [ The frontend fetches this JSON and renders it using the Prefab React bundle. OPTION 3 — Static export served by DjangoExport your Prefab UI as a self-contained HTML file and serve it through Export the UIprefab export my_ui.py --output ui/dist/ In Django settings.py, add the output folder to STATICFILES_DIRSSTATICFILES_DIRS = [BASE_DIR / "ui" / "dist"] Serve it from a Django viewfrom django.shortcuts import render def ui_view(request): This approach requires no running Prefab process in production — just WHAT DOES NOT WORK
RECOMMENDED SETUP FOR MOST PROJECTSUse Option 1 (separate services) for development and production. nginx.conf (simplified)location /api/ { This keeps both services independent and easy to scale separately. USEFUL LINKS
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible (or compatible) to use with django or not? (If yes can you explain how?)
Beta Was this translation helpful? Give feedback.
All reactions