Skip to main content

Run a Django backend (Django ORM, Django Admin) alongside a Reflex app.

Project description

reflex-django

Keep Django. Get a reactive UI in Python. One process, shared cookies, native Reflex dev.

PyPI Python Docs License

Documentation · GitHub · PyPI


What is it?

You love Django. You also want a modern, reactive UI in Python, not a separate React repo.

reflex-django runs Django and Reflex together on one origin with shared session cookies. Reflex handlers see the same request.user as Django admin and your API.

  • Same cookiesself.request.user inside every @rx.event
  • Same middleware — your full settings.MIDDLEWARE chain on events
  • Django admin + ORM — keep models, migrations, and admin as-is
  • Two dev ports — Vite on :3000, backend on :8000 (proxies wire admin/API for you)

New or existing?

You already have Integration guide Dev command
A Django project Existing Django project python manage.py run_reflex
A Reflex project (move config to settings) Existing Reflex project python manage.py run_reflex
A Reflex project (keep rxconfig.py) Reflex plugin path reflex run

Django-first (default): config in settings.py (RX_CONFIG), pages in views.py, from reflex_django import app.

Reflex-first (plugin): add ReflexDjangoPlugin(config={...}) to rxconfig.py, keep app = rx.App(), use reflex run / reflex export.

Both paths need a Django shell (manage.py, settings.py, urls.py) for ORM, admin, and migrations.


Minimal setup (new Django project)

uv add django reflex reflex-django

config/settings.py:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "reflex_django",
    "shop",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    "reflex_django.bridge.streaming.AsyncStreamingMiddleware",
]

RX_CONFIG = {
    "app_name": "shop",
    "frontend_port": 3000,
    "backend_port": 8000,
}

config/urls.py:

import shop.views  # noqa: F401

from django.contrib import admin
from django.urls import path

urlpatterns = [path("admin/", admin.site.urls)]

config/asgi.py:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

from django.core.asgi import get_asgi_application

application = get_asgi_application()  # noqa: E402,F401

shop/views.py:

import reflex as rx
from reflex_django.pages.decorators import page
from reflex_django.states import AppState


class HomeState(AppState):
    @rx.event
    async def on_load(self):
        user = self.request.user
        self.greeting = (
            f"Hi, {user.get_username()}!"
            if user.is_authenticated
            else "Hello, guest. Log in at /admin/."
        )


@page(route="/", title="Home", on_load=HomeState.on_load)
def index() -> rx.Component:
    return rx.vstack(
        rx.heading("My Shop"),
        rx.text(HomeState.greeting),
    )

Run:

python manage.py migrate
python manage.py run_reflex

Open http://localhost:3000/ for the Reflex UI. Admin at http://localhost:8000/admin/ (or via :3000 when Vite proxies are active).


Existing Django project

You keep models, admin, DRF, and webhooks. You add:

  1. reflex-django to INSTALLED_APPS and RX_CONFIG in settings.py
  2. @page functions in {app}/views.py (import the module in urls.py)
  3. python manage.py run_reflex for local dev

Full walkthrough: Add to an existing Django project


Existing Reflex project

You keep page components and most event handlers. You wrap the app in a Django shell for ORM, admin, and sessions.

Option A — settings path (recommended for long-term Django-first layout):

  • Move rxconfig.py fields → RX_CONFIG in settings.py
  • Replace app = rx.App() with from reflex_django import app (or keep pages in views.py with @page)
  • Dev: python manage.py run_reflex

Guide: Add to an existing Reflex project

Option B — plugin path (minimal change, keep Reflex CLI):

# rxconfig.py
from reflex_django.plugins import ReflexDjangoPlugin

config = rx.Config(
    app_name="myshop",
    plugins=[
        ReflexDjangoPlugin(config={
            "settings_module": "config.settings",
            "django_prefix": ("/admin", "/api"),
        }),
    ],
)

Keep app = rx.App() in {app}/{app}.py. Dev: reflex run, reflex export, reflex deploy.

Guide: Plugin path for existing Reflex


Read the docs

Start here on the docs site:

  1. Getting started — install, quickstart, project layout
  2. Your first app — todo tutorial
  3. Troubleshooting — ports, proxies, CSRF

More essentials:

Full site: https://web7ai.github.io/reflex-django/


Versions

Version
reflex-django 3.0+
Python 3.12+
Django 6.0+
Reflex 0.9.4+

Upgrading from 2.x? See the v3 migration guide.


Common commands

# Django-first (default)
python manage.py run_reflex
python manage.py run_reflex --env dev      # single-port compile dev
python manage.py export_reflex             # build SPA for deploy

# Reflex-first (with ReflexDjangoPlugin in rxconfig.py)
reflex run
reflex export

# Django (both paths)
python manage.py migrate
python manage.py createsuperuser

Author: Mohannad Irshedat · GitHub · Docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reflex_django-3.0.0.tar.gz (252.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reflex_django-3.0.0-py3-none-any.whl (247.3 kB view details)

Uploaded Python 3

File details

Details for the file reflex_django-3.0.0.tar.gz.

File metadata

  • Download URL: reflex_django-3.0.0.tar.gz
  • Upload date:
  • Size: 252.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for reflex_django-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9f9ce5a3f048243d8d37c45c7c436aa6028b636acbfeef3d3dfa2fbb28b1e784
MD5 3b612085805023ddb8622ef885a043c1
BLAKE2b-256 6cd4d8c225c68ae439dc5dd714ad5394a17e8013c613880bd7ddd15103953e75

See more details on using hashes here.

File details

Details for the file reflex_django-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: reflex_django-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 247.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for reflex_django-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b741ae67692f08ca3e8c4f63d25cdb22b98e0665f5a71f553052a43be32e8b02
MD5 c2c87a29a13da4098ae8e4a17bfaee27
BLAKE2b-256 69f2aca55c4fac589a89a2916761f8cecd85d0f477252589fdd7f7b090727492

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page