Getting started
How to bootstrap a new project using Prefab as a foundation.
1. Create the project settings
Create a settings file that imports from Prefab and extends it:
python
# myproject/settings/base.py
from prefab.settings.base import *
PROJECT_NAME = 'myproject'
PROJECT_PATH = os.path.join(os.path.dirname(__file__), '../')
BASE_DOMAIN = 'example.com'
SITE_NAME = 'My Project'
SITE_URL = 'https://%s' % BASE_DOMAIN
SITE_EMAIL = 'hello@%s' % BASE_DOMAIN
SITE_SLOGAN = 'Tagline here'
ROOT_URLCONF = 'myproject.urls'
STATIC_ROOT = os.path.join(PROJECT_PATH, '../static')
STATICFILES_DIRS = (os.path.join(PROJECT_PATH, 'assets'),)
MEDIA_ROOT = os.path.join(PROJECT_PATH, '../media')
INSTALLED_APPS += [
'myproject',
'myproject.apps.myapp',
]python
# myproject/settings/development.py
from myproject.settings.base import *
from prefab.settings.development import *python
# myproject/settings/production.py
from myproject.settings.base import *
from prefab.settings.production import *See prefab/settings/example.py for a full reference settings file.
2. Create the URL configuration
Prefab's prefab.urls provides a base URL configuration you can include or use as a reference. A typical project wires it like this:
python
# myproject/urls.py
from prefab.urls import urlpatterns # includes admin, account, webhooks, health
from django.urls import path, include
urlpatterns += [
path('', include('myproject.apps.pages.urls')),
]Pre-wired routes (from prefab.urls):
| URL | Description |
|---|---|
admin/django/ | Django built-in admin |
admin/ | Prefab admin2 dashboard |
account/ | Accounts app (login, register, etc.) |
webhooks/ | Webhooks app |
robots.txt | Robots template |
healthz/ | Health check endpoint |
3. Set up the Dockerfile
Inherit from the Prefab Docker image. The ONBUILD instructions in the Prefab image automatically:
- Copy your
requirements.txtand install it (build stage) - Copy your project files into
/app/(runtime stage) - Copy all compiled Python packages and binaries from the build stage
dockerfile
ARG PREFAB_VERSION=latest
FROM registry.gitlab.com/baksteen/prefab:${PREFAB_VERSION}If your project has additional native build dependencies, extend the build stage:
dockerfile
FROM registry.gitlab.com/baksteen/prefab:${PREFAB_VERSION} AS build
RUN apt-get install -y --no-install-recommends my-build-dep
FROM registry.gitlab.com/baksteen/prefab:${PREFAB_VERSION}4. Set up docker-compose for local development
yaml
# docker-compose.yml
volumes:
postgres:
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: myproject
POSTGRES_PASSWORD: postgres
volumes:
- postgres:/var/lib/postgresql/data
redis:
image: redis
web:
build: .
environment:
DJANGO_SETTINGS_MODULE: myproject.settings.development
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- 8000:8000
depends_on:
- postgres
- redis5. Run migrations and create a superuser
bash
make migrations
make superuserOr directly:
bash
docker compose run --rm web python manage.py migrate
docker compose run --rm web python manage.py createsuperuser6. Optional apps
Enable additional Prefab apps by adding them to INSTALLED_APPS:
python
INSTALLED_APPS += [
'prefab.apps.pages',
'prefab.apps.blocks',
'prefab.apps.regions',
'prefab.apps.forms',
'prefab.apps.subscriptions',
'prefab.apps.websites',
]Each app may require additional URL wiring and migrations — see the individual app READMEs.