# Add e-signatures and clickwrap to Django

> Add e-signatures and clickwrap to Django with four views and requests: POST /v1/sessions, GET /v1/records, the session and the CSRF cookie. Tested code.

Source: https://esigncomply.com/django

Stack · Django

To add e-signatures and clickwrap to Django, call the REST API from your views: there is no Python package, because the server SDK exists for Node.js only. One view creates the session with the secret key and keeps the pinned versions in the Django session, and another view confirms the record. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/django)

`pip install django requests`

[Django quickstart](https://esigncomply.com/docs/quickstart/django)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run in Django before publishing

**Session view**

mysite/views.py (excerpt)

```python
# Step 4: create the session with the secret key. The browser gets the client token only.
@require_POST
def ceremony(request):
    origin = request.headers.get("Origin") or f"{request.scheme}://{request.get_host()}"
    status, session = esign.call(
        "POST",
        "/sessions",
        idempotency_key=f"signup-{SIGNER['external_id']}-{uuid.uuid4()}",
        json={
            "profile": os.environ["ESIGNCOMPLY_PROFILE_ID"],
            "signer": SIGNER,
            "documents": [
                {"document": DOCUMENTS["terms"], "version": "current"},
                {"document": DOCUMENTS["privacy"], "version": "current"},
            ],
            "context": {"url": f"{origin}/signup", "locale": "en-US", "purpose": "account_signup"},
        },
    )
    if status != 201:
        return JsonResponse({"error": session.get("error", {}).get("code")}, status=502)
    # The Django session is stored on the server: the browser holds only its ID.
    request.session["pinned_versions"] = sorted(d["version_id"] for d in session["documents"])
    return JsonResponse(
        {"clientToken": session["client_token"], "apiUrl": session["api_url"], "documents": session["documents"]}
    )
```

**The API call**

mysite/esign.py (excerpt)

```python
def call(method, path, json=None, idempotency_key=None):
    """One call to the Esign Comply API. Returns (status, parsed JSON)."""
    headers = {"Authorization": f"Bearer {os.environ['ESIGNCOMPLY_API_KEY']}"}
    if idempotency_key:
        headers["Idempotency-Key"] = idempotency_key
    for attempt in range(3):
        response = requests.request(method, API + path, headers=headers, json=json, timeout=10)
        # Over the rate limit: wait for Retry-After (5 seconds at most) and try again, twice at most. Nothing else is retried.
        if response.status_code != 429 or attempt == 2:
            break
        time.sleep(min(float(response.headers.get("Retry-After") or 1), 5))
    return response.status_code, response.json()
```

**Confirm view**

mysite/views.py (excerpt)

```python
# Step 6: confirm the record with the secret key before the account exists.
@require_POST
def confirm(request):
    record_id = json.loads(request.body or b"{}").get("recordId")
    status, record = esign.call("GET", f"/records/{quote(str(record_id), safe='')}")
    confirmed = (
        status == 200
        and record["status"] in SEALED
        and record["livemode"] is LIVE
        and record["signer"]["external_id"] == SIGNER["external_id"]
        and sorted(d["version_id"] for d in record["documents"]) == request.session.get("pinned_versions")
    )
    print(f"confirmed {record['id']} ({record['status']})" if confirmed else "refused", flush=True)
    if not confirmed:
        return JsonResponse({"confirmed": False}, status=409)
    # Only now create the account, and store record["id"] and record["receipt"] with it.
    return JsonResponse({"confirmed": True, "recordId": record["id"]})
```

Integrate with Django

## How do you integrate Esign Comply with Django?

In Django the integration is four views and no new app. `request.session` holds the versions the server pinned, so nothing sits in memory and a first run needs no model. The signup page is a plain file, so its view carries `@ensure_csrf_cookie` and the script sends the token back as `X-CSRFToken`.

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.

Source: [djangoproject.com](https://www.djangoproject.com/), read on November 24, 2026.

[Django quickstart](https://esigncomply.com/docs/quickstart/django) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in Django

- **Session view** · `mysite/views.py`
- **The API call** · `mysite/esign.py`
- **Confirm view** · `mysite/views.py`

Run on 2026-11-26 with Django 4.2.30 and requests 2.32.5 on Python 3.9.25, with the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode.

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Django app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes in Django, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap in Django

```
Add Esign Comply clickwrap to my Django app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/django.md (the steps and the tested code for Django)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Django facts
- There is no Esign Comply package for Python. Do not install or invent one. The views call the REST API at https://esigncomply.com/v1 with Authorization: Bearer and the secret key.
- The browser SDK is a script tag: https://esigncomply.com/sdk/v1/esigncomply.js. It defines the global EsignComply.
- The secret key is in the environment variable ESIGNCOMPLY_API_KEY. Django does not read .env files on its own. Never print the key.
- Every POST from the page carries Django's CSRF token in the X-CSRFToken header. A page that is not a template needs @ensure_csrf_cookie on its view to get the csrftoken cookie.
- Keep the pinned version IDs in request.session. The default session lives in the database, so run python manage.py migrate first.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. View for POST /api/ceremony: call POST /v1/sessions with an Idempotency-Key, save the pinned version IDs in request.session, and return only clientToken, apiUrl and documents.
4. View for GET /legal/<slug>: render the html from GET /v1/documents/{id}/versions/{version_id}/content inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. View for POST /api/signup/confirm: call GET /v1/records/{id} and require: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the server-owned state. Only then create the account.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:8000/signup --callback http://localhost:8000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures in Django?

These are specific to Django. Each one was seen while the quickstart's code was run, or is in Django's own documentation.

- **A page without the csrf_token tag gets no CSRF cookie**

  Django's documentation says a view that renders no `csrf_token` tag might not set the cookie. In the test run a view without `@ensure_csrf_cookie` set none, and a POST without the `X-CSRFToken` header was answered `403` before any view ran. The decorator on the signup view fixes both.

  Source: [Django documentation, How to use Django's CSRF protection](https://docs.djangoproject.com/en/4.2/howto/csrf/), read on November 24, 2026.

- **The session needs its table before the first request**

  The quickstart keeps the pinned versions in `request.session`, which Django stores in the database by default. Before `python manage.py migrate`, the session view answered `500` with `no such table: django_session` in the test run.

- **runserver is for development**

  The quickstart starts Django with `python manage.py runserver`. Django's documentation says of it: do not use this server in a production setting. Serve the project with your production server before you switch to the live key.

  Source: [Django documentation, django-admin and manage.py](https://docs.djangoproject.com/en/4.2/ref/django-admin/), read on November 24, 2026.

## Where are the Django quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Django quickstart](https://esigncomply.com/docs/quickstart/django)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Long guide

  **[Clickwrap in Django](https://esigncomply.com/guides/django-clickwrap)**

  The full signup app: a model that stores the acceptance, the signer's own details, the views and the webhook.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature in Django?

The same record on every stack and platform. Your Django code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures in Django

### Is there an Esign Comply SDK for Django?

No. The server SDK exists for Node.js only. Django calls the REST API directly with the secret key, and the quickstart does it with `requests` in one short function. The browser side is the same SDK as on every stack, loaded from a script tag.

### Where do I create the session in Django?

In a view that handles `POST /api/ceremony`, with a call to `POST /v1/sessions` that carries the secret key and an `Idempotency-Key`. The view returns only the client token, the API URL and the pinned documents to the browser.

### Does the Django session keep the pinned versions on the server?

Yes. Django's default session engine stores the data in the database and gives the browser a cookie with the session ID only. The visitor cannot read or change the version IDs the server pinned when it created the session.

### Do I need to add an app to INSTALLED_APPS?

No. The quickstart adds four views, one module with the API call and one HTML file to the project package, and replaces `urls.py`. It changes nothing in `settings.py`, because sessions and the CSRF middleware are already on in a new project.

### Why does the signup view carry ensure_csrf_cookie?

Because the page is a plain file with no `csrf_token` template tag, and its script needs the `csrftoken` cookie to send the token back. In the test run the signup view set the cookie and a view without the decorator set none.

### Other stacks

- [Python](https://esigncomply.com/python)
- [FastAPI](https://esigncomply.com/fastapi)
- [Rails](https://esigncomply.com/rails)

### Platforms used with Django

- [Supabase](https://esigncomply.com/supabase)
- [Vercel](https://esigncomply.com/vercel)

[All stacks](https://esigncomply.com/stacks) · [All platforms](https://esigncomply.com/platforms) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Add four views to your Django project. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/django)

Free plan: 10 live signatures a month and a full test mode. No card required.

Django is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Django is from Django's documentation or from a test run, as marked, on November 24, 2026. `/django.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
