Skip to main content

Automatically run the Django dev server on a particular hostname

Project description

Run Server on Hostname

My problem: I have multiple Django projects, but when I use the dev server (./manage.py runserver), they clobber each others' cookies since they run at 127.0.0.1 by default.

The manual solution: I set my hostfile (/etc/hosts) up so that each project has its own pseudo-hostname. Usually this is "projectname.localhost". But that means I have to remember which name I gave to each project and remember to pass it every time I ./manage runserver.

This package lets me define a desired dev server hostname in my Django settings, then runserver will respect it by default. If for any reason, I want to override that setting on a one-off basis, that still works.

Installation

  1. Install the django-runserveronhostname package using whatever package manager you prefer (I use uv).
  2. Add runserveronhostname to INSTALLED_APPS in your Django settings.
  3. Add a setting RUNSERVER_ON = 'myname.whatever:8000' (you must include a port number). This could also be used to bind to a particular IP address (RUNSERVER_ON = '0.0.0.0:8000') if you prefer.

Important note: this package doesn't do anything about making sure you can actually bind to the requested name or IP address. You will need to manually add an entry to your hostfile, DNS, etc.

Usage

When you run the dev server (./manage.py runserver, django-admin runserver, etc.), if you have RUNSERVER_ON defined, it'll use that. This works with any runserver implementation:

  • naive implementation in Django
  • staticfiles implementation in Django
  • daphne's runserver override

Contributing

While I don't mind contributions, I don't really expect any, either. So I don't have great instructions here. It's a really small package, and you can probably stand up a little test app locally with this installed in editable mode.

Running tests

At time of writing, we have 100% test coverage. That's not necessarily a strict rule, but it sure feels good to have a second set of eyes watching each line.

% uv sync --extra test && uv run pytest

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

django_runserveronhostname-0.2.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_runserveronhostname-0.2.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file django_runserveronhostname-0.2.0.tar.gz.

File metadata

  • Download URL: django_runserveronhostname-0.2.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_runserveronhostname-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d14306fb4077aa05d3a52fb1ed99dc992be4cd480e9de7b23431e7a3574f3c0b
MD5 c9827b93b603df5088f651b41b93d92c
BLAKE2b-256 7489ef69db2a034b620a76c3d80061bca334c8836a761ba54dc69501813d8aff

See more details on using hashes here.

File details

Details for the file django_runserveronhostname-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_runserveronhostname-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_runserveronhostname-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45f33b7a773c5c2925fb72e2a5f25a016853f00ca7b1f6b01c2e64a72497b254
MD5 08b5d48092b6e2221554e3f5018a72c1
BLAKE2b-256 5b5e0142e43aaf3ea1379de4f7c7b6886f0c64f5da20530a74e844d2a690487e

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