Skip to content

Share localhost / Django

Share a Django dev server at a public URL

python manage.py runserver listens on 127.0.0.1:8000, and whk share 8000 gives it an HTTPS link. Pages load with your settings untouched; forms need one line, because Django compares each POST's origin with the host it sees.

# terminal 1: the dev server
python manage.py runserver

# terminal 2: the link
whk share 8000

The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.

Start free:
or sign up with email

Django at a glance

Dev server
python manage.py runserver, port 8000
Share it
whk share 8000
Setting to add
CSRF_TRUSTED_ORIGINS = ["https://*.sharehooks.cc"] in settings.py. ALLOWED_HOSTS can stay as it is.
Without it
Pages load, but every form POST answers 403 Forbidden with Origin checking failed - https://<name>.sharehooks.cc does not match any trusted origins.
Hot reload
runserver reloads Python code as it changes, so visitors get your edit on their next request. It does not refresh the browser.
URLs and cookies
build_absolute_uri() returns http://localhost:8000/... unless USE_X_FORWARDED_HOST and SECURE_PROXY_SSL_HEADER are set, together with ALLOWED_HOSTS. Cookie defaults work.

Your dev server gets each request with Host: localhost:8000; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.

ALLOWED_HOSTS is already satisfied

With DEBUG = True and an empty ALLOWED_HOSTS, Django validates the host against ['.localhost', '127.0.0.1', '[::1]']. The link sends Host: localhost:8000, so a fresh project serves its pages through a share with no change.

The error most tunnel guides are about, Invalid HTTP_HOST header: '<name>'. You may need to add '<name>' to ALLOWED_HOSTS. with status 400, belongs to tunnels that pass the public name as Host. You will only meet it here if you turn on USE_X_FORWARDED_HOST, which is covered below.

Trust the preview's origin for forms

For a POST that carries an Origin header, Django's CSRF protection requires it to match the origin of the host it sees. The browser sends Origin: https://<name>.sharehooks.cc; Django sees http://localhost:8000. The form answers 403 with the reason Origin checking failed - https://<name>.sharehooks.cc does not match any trusted origins.

List the origin in CSRF_TRUSTED_ORIGINS. Values need their scheme, and * stands for a subdomain:

settings.py

# Previews opened with whk share
CSRF_TRUSTED_ORIGINS = ["https://*.sharehooks.cc"]

That one setting is enough for login forms, the admin and your own views. The wildcard trusts every preview name, other people's included; with a reserved name, list only yours: ["https://acme.sharehooks.cc"].

Absolute URLs behind the link

request.build_absolute_uri() and request.get_host() go by the Host header, so they say http://localhost:8000. Relative links and redirects are unaffected, and a redirect to that address comes back to the link. If you need the public address in an email, a sitemap or an OAuth callback, tell Django to read the forwarded headers:

settings.py

# Only while sharing: the link sets these headers on every request
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
ALLOWED_HOSTS = [".sharehooks.cc", "localhost", "127.0.0.1"]

Set all three together. USE_X_FORWARDED_HOST alone makes every request fail the host check with status 400, since the forwarded name is then validated against ALLOWED_HOSTS; SECURE_PROXY_SSL_HEADER alone leaves the CSRF check comparing against https://localhost:8000. With the three in place Django sees the public origin itself, and forms pass without CSRF_TRUSTED_ORIGINS. Take them out again for direct local use: Django's docs warn against trusting these headers when no proxy sets them.

Static files, cookies and the debug page

runserver serves static files itself when DEBUG is on and django.contrib.staticfiles is installed, on the same port, so styles and scripts come through the link. The session and CSRF cookies are set without a domain and without Secure by default, which works on the link as it does locally.

DEBUG = True also means a visitor who triggers an error sees Django's debug page, with settings and local variables. Share what you would show, or put a password on the share.

Django questions

Sources

The Django settings and messages on this page are from the official documentation and source for Django 6.1, read on 12 November 2026. What the link does to a request is from the whk share docs.

Other frameworks

All 14 framework guides

Send someone your Django app

Sign up free, install the CLI and run whk share 8000.

or sign up with email

No credit card