Skip to content

Django Integration

  • Automatic Dependency Management


    Inject dependencies in routes and automatically manage container lifecycle.

  • Request Objects


    Use Django request in Wireup dependencies.

  • Django Settings


    The integration exposes Django settings to Wireup as config.

  • Shared business logic


    Wireup is framework-agnostic. Share the service layer between web applications and other interfaces, such as a CLI.

Quick Start

This is the shortest path to a working endpoint with explicit injection.

settings.py
from wireup.integration.django import WireupSettings

INSTALLED_APPS = [
    # ...existing apps...
    "wireup.integration.django",
]

MIDDLEWARE = [
    "wireup.integration.django.wireup_middleware",
    # ...existing middleware...
]

WIREUP = WireupSettings(
    injectables=["mysite.services"],
    auto_inject_views=False,
)
mysite/services.py
from wireup import injectable


@injectable
class GreeterService:
    def greet(self, name: str) -> str:
        return f"Hello {name}"
mysite/views.py
from django.http import HttpRequest, HttpResponse
from wireup import Injected
from wireup.integration.django import inject

from mysite.services import GreeterService


@inject
def greet(
    request: HttpRequest, greeter: Injected[GreeterService]
) -> HttpResponse:
    return HttpResponse(greeter.greet(request.GET.get("name", "World")))
mysite/urls.py
from django.urls import path

from mysite.views import greet

urlpatterns = [
    path("greet/", greet),
]

Run the app with python manage.py runserver, then open http://127.0.0.1:8000/greet/?name=World.

Detailed Guides

API Reference