Common Configuration: ORMBridge, CORS, and Pusher Setup
Now we will create some test models to work with:
1. Install the ORMBridge Package
Install ORMBridge via pip:
bash
pip install git+https://github.com/ormbridge/ormbridgeThen, add it to your Django apps in your settings file (e.g., /backend/backend/settings.py):
python
INSTALLED_APPS = [
# ...
'ormbridge.adaptors.django',
# ...
]2. Configure CORS for Development
Install CORS Headers
bash
pip install django-cors-headersUpdate Your Settings File (common.py)
- Add the CORS App:python
INSTALLED_APPS = [ # ..., "corsheaders", # ... ] - Insert the CORS Middleware at the Top:python
MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', # must be at the top # ... your other middleware ] - Specify Allowed Origins:python
CORS_ALLOWED_ORIGINS = [ "http://localhost:5173", # Vite default (Vue, React) ]
3. Add ORMBridge URLs
Edit your root URL configuration file (typically /backend/backend/urls.py):
python
from django.urls import path, include
urlpatterns = [
# ... your other URL patterns
path('ormbridge/', include('ormbridge.adaptors.django.urls', namespace='ormbridge')),
]Test by running:
bash
python manage.py runserverYou should see a message similar to:
ORMBridge is running but no models are registered.4. Set Up Real-Time Updates with Pusher
Create a Pusher Account & App
- Sign up at Pusher.
- Create a new Pusher Channels app.
- Note your App ID, Key, Secret, and Cluster.
Configure Pusher in Your Settings File (common.py)
python
ORMBRIDGE_PUSHER = {
'APP_ID': 'your-pusher-app-id',
'KEY': 'your-pusher-key',
'SECRET': 'your-pusher-secret',
'CLUSTER': 'your-pusher-cluster',
}5. Run Migrations and Start the Server
Apply migrations and launch your Django server:
bash
python manage.py makemigrations
python manage.py migrate
python manage.py runserverWith these common configurations in place, your project is set up to use ORMBridge, handle CORS during development, and push real-time updates via Pusher.