Automated PyCharm Runserver Configurations for a Multi-Subdomain Django Project
If you've ever worked on a Django project that serves multiple subdomains — a public-facing site on www and a separate app on app, for example — you'll know that getting your local environment to mirror that setup takes a surprising amount of fiddling. Modern Django projects commonly map several domains to the same project, each with its own settings module, port, and purpose. Getting all of that running consistently across a team shouldn't be a chore.
That's exactly what this script is for. Instead of manually editing /etc/hosts and clicking through PyCharm's run configuration dialogs every time someone joins the project or rebuilds their machine, you run a single command and everything is taken care of. It registers www.myproject.localhost and app.myproject.localhost in your system /etc/hosts file, so your browser and Django's ALLOWED_HOSTS both resolve them correctly — just like they would in production.
Because the configurations are generated programmatically from a template, every developer on the team ends up with an identical setup — same hostnames, same ports, same settings modules, no variation. There's no "works on my machine" when the machine is configured by the same script. Commit it to your repository and local environment setup becomes a one-liner for anyone who clones the project.
It's also idempotent — friendly to repeat runs. Already have some hosts entries from a previous setup? The script checks before writing and skips anything that's already there. Run configuration files are simply refreshed from the template. That makes it just as useful for keeping a team in sync as it is for first-time setup.
The script is deliberately easy to adapt. Swap in your project's subdomains, ports, and settings modules, drop it in the repository root alongside the template, and you have a reusable bootstrapper that travels with every new Django project you start. Whether you're onboarding a new teammate, rebuilding after a fresh OS install, or kicking off a brand new project, this script gets everyone to the same starting point in seconds — so you can spend your time on the project, not the plumbing.
Programming Django 6.x Django 5.2 Django 4.2 PyCharm
If you find this goodie useful and would like to support me with coffee, meal, audiobook, or an online course, you can donate to me at paypal.me/aidasbendoraitis.
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.