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
- Install the
django-runserveronhostnamepackage using whatever package manager you prefer (I useuv). - Add
runserveronhostnametoINSTALLED_APPSin your Django settings. - 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. See the new hostfile command for some help with that.
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
staticfilesimplementation in Djangodaphne's runserver override
hostfile command
You can run ./manage.py hostfile to see whether the hostname you require is listed in your system host file. Right now this only works directly on Linux and macOS, but if you know where your system's hostfile lives, you can point to it with ./manage hostfile --file <path/to/hosts>.
There's another option you can pass, --write, which will spit back the hostfile it finds and add your project's RUNSERVER_ON hostname if it doesn't already appear. If you wanted to be really bold, you could do something like:
# I don't really recommend this, it's not battle-tested
% sudo ./manage.py hostfile --write >/etc/hosts
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
Changelog
See what's changed in each version in the changelog.
Metadata
Release files for django-runserveronhostname 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_runserveronhostname-0.3.0.tar.gz | 4.9 kB | Without provenance | Details for django_runserveronhostname-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_runserveronhostname-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for django_runserveronhostname-0.3.0-py3-none-any.whl |
Total release size: 12.4 kB
Release files / django_runserveronhostname-0.3.0.tar.gz
| Download URL | django_runserveronhostname-0.3.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c599096f0893b6836970a1cf18fdeccce1e70b74c35228d67a17ef8ab77f255a
|
|
BLAKE2b-256 checksum How to use checksums |
201b1f8468f534ff578d81785f14605b5b4cb12037aaad007f2384f2c3fe9163
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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}
|
Release files / django_runserveronhostname-0.3.0-py3-none-any.whl
| Download URL | django_runserveronhostname-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
743c9ff553cd28015200167145238d66fd7e1d05f0b81176e278a4b8b2a82951
|
|
BLAKE2b-256 checksum How to use checksums |
7cf8ebae9ff36fc783926c7c85acf2ea557ddc0e76b9592bcae74c73ff1b8d08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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}
|
Security for django-runserveronhostname 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.