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 Reflex + Django project Plugin integration reflex run

Add ReflexDjangoPlugin to rxconfig.py, keep app = rx.App() in {app}/{app}.py, and use normal Django settings for ORM, admin, and migrations.


Minimal setup

uv add django reflex reflex-django

rxconfig.py:

import reflex as rx
from reflex_django.plugins import ReflexDjangoPlugin

config = rx.Config(
    app_name="shop",
    frontend_port=3000,
    backend_port=8000,
    plugins=[
        ReflexDjangoPlugin(config={
            "settings_module": "config.settings",
            "django_prefix": ("/admin", "/api"),
            "mount_prefix": "/",
            "auto_mount": True,
        }),
    ],
)

config/settings.py (Django only — no RX_CONFIG):

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",
]

shop/shop.py:

import reflex as rx

app = rx.App()

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:

reflex django migrate
reflex run

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


Dev proxy: RX_PROXY_SERVER (optional)

Default — leave unset. reflex run mounts Django inside the Reflex backend on :8000. Vite on :3000 proxies admin, API, /_event, and the SPA to that single backend. One command, shared cookies on the browser origin.

Split Django — set when Django runs separately. If you prefer python manage.py runserver in its own terminal (or Django on another host), point reflex-django at it:

# config/settings.py
RX_PROXY_SERVER = "http://127.0.0.1:8000"

Then:

# Terminal 1
python manage.py runserver

# Terminal 2
reflex run

Vite still serves the SPA on :3000, but /admin and /api proxy to your Django server; /_event and other Reflex paths stay on the Reflex backend. reflex-django skips in-process Django dispatch when RX_PROXY_SERVER is set.

Default (unset) RX_PROXY_SERVER set
Django Mounted in Reflex backend Separate runserver (or other HTTP server)
Dev commands reflex run only runserver + reflex run
Typical use Most projects Django-only debugging, familiar two-process dev

This is a dev-only setting. Production uses your reverse proxy and plain Django ASGI — not RX_PROXY_SERVER.

More: Local development · Routing


Existing projects

Add Django (manage.py, settings.py, urls.py), put ReflexDjangoPlugin in rxconfig.py, and use reflex run.

Guide: Plugin integration

v3 → v4 migration: v4 plugin-only


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 4.0+
Python 3.12+
Django 6.0+
Reflex 0.9.4+

Upgrading from 3.x? See the v4 migration guide.


Common commands

reflex run
reflex export
reflex django migrate
reflex django 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-4.0.0.tar.gz (208.6 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-4.0.0-py3-none-any.whl (209.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reflex_django-4.0.0.tar.gz
  • Upload date:
  • Size: 208.6 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-4.0.0.tar.gz
Algorithm Hash digest
SHA256 2824c20fe814f6bb348f6d21555118abdeac9bada44bc7e10777f09a8290d948
MD5 8e40d2d21a5704e9981cb87c0065853b
BLAKE2b-256 c91ab35a6acbf7e0be62c6c32082f087820250caef7e981066a4acfde8cba15a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reflex_django-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 209.6 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-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d08587174dc12649f5d3eaa012cc71d561cea23992522b36f16fd5459ec6051
MD5 d6199619b8d88d36b88dd370ccd685cc
BLAKE2b-256 d7472a3f6449d112c2de68c579032ddf938acbb98d51e0b58e557647aa372c52

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