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. Reflex config lives in settings.py. Pages live in views.py. The SPA catch-all mounts automatically. The session from /admin/login/ is the same session your Reflex handlers see.

  • One commandpython manage.py run_reflex
  • Same cookiesself.request.user inside every @rx.event
  • Same middleware — your full settings.MIDDLEWARE chain on events
  • Two dev ports — Vite on :3000, backend on :8000 (proxies wire admin/API for you)

Minimal setup

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.streaming_middleware.AsyncStreamingMiddleware",
]

REFLEX_DJANGO_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 reflex_django.asgi_entry import 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).


Read the docs

Start here on the docs site:

  1. Learning path — pick your route from zero to shipping
  2. Your first app — 15-minute todo tutorial
  3. Troubleshooting — when ports, proxies, or CSRF fight back

More essentials:

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


Versions

Version
Python 3.12+
Django 6.0+
Reflex 0.9.4+

Common commands

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
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-1.0.0.tar.gz (260.5 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-1.0.0-py3-none-any.whl (243.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reflex_django-1.0.0.tar.gz
  • Upload date:
  • Size: 260.5 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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2466d25d516a2ea3d6818a93f47ccf9a68fe08c3a4f16c2d1a0e2e2fbe545061
MD5 5811a562a94203615297bc1ea0a95b54
BLAKE2b-256 88b1ff3ecbc650613bf0378300b852d22f3acf156deffb79d50623a3a22d3361

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reflex_django-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 243.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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc0716d012469b0bb515ccd8ee62707e107d5c75a7dcd384bb454c43b5dfec8a
MD5 96d3116af09c2449a1cf7f5af0cb8a82
BLAKE2b-256 1fbf3168a96aa3125bacd9964aa43290d9f685bbb3e6b9ecebabceff32e0783a

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