Takk

Deploy

Django

This guide walks you through deploying a Django application on Takk. Django is a batteries-included web framework for Python. While Takk doesn't have a dedicated Django app type, you can deploy Django using the NetworkApp configuration, which gives you full control over the startup command and port.

Prerequisites

Make sure you have the Takk CLI installed and are logged in. If not, follow the Get Started guide first.

Create the Project

Start by creating a new directory and initializing it:

bash
mkdir django-hello
cd django-hello
uv init

Add your dependencies:

bash
uv add django gunicorn takk

Create the Django App

Use the Django CLI to scaffold a new project:

bash
uv run django-admin startproject hello .

Then create a simple view. Edit hello/views.py:

python
from django.http import JsonResponse

def index(request):
    return JsonResponse({"message": "Hello, World!"})

def greet(request, name):
    return JsonResponse({"message": f"Hello, {name}!"})

Wire up the URLs in hello/urls.py:

python
from django.urls import path
from hello.views import index, greet

urlpatterns = [
    path("", index),
    path("greet/<str:name>/", greet),
]

Update hello/settings.py to allow all hosts (required for containerized deployments):

python
ALLOWED_HOSTS = ["*"]

Define the Project

Create project.py to tell Takk how to run Django:

python
from takk.models import Project, NetworkApp

project = Project(
    name="django-hello",
    server=NetworkApp(
        command=["gunicorn", "hello.wsgi:application", "--bind", "0.0.0.0:8000"],
        port=8000,
    ),
)

The NetworkApp lets you specify any startup command and port. Here we use Gunicorn to serve the Django application, which is the recommended production setup.

Run Locally

Start the local development environment:

bash
uv run takk up

Your Django app is now running at http://localhost:8000. Test it:

bash
curl http://localhost:8000
# {"message": "Hello, World!"}

curl http://localhost:8000/greet/Alice/
# {"message": "Hello, Alice!"}

Deploy

Deploy to the cloud with:

bash
uv run takk deploy

Takk builds the container, provisions infrastructure, and starts your Django application. TLS and networking are handled automatically.

Next Steps

Previous
FastAPI