I would like to make the default port that manage.py runserver
listens on specifiable in an extraneous config.ini
. Is there an easier fix than parsing sys.argv
inside manage.py
and inserting the configured port?
The goal is to run ./manage.py runserver
without having to specify address and port every time but having it take the arguments from the config.ini
.
All of the following commands are possible to change the port while running django:
Actually the easiest way to change (only) port in development Django server is just like:
that should run development server on http://127.0.0.1:7000/
We created a new 'runserver' management command which is a thin wrapper around the standard one but changes the default port. Roughly, you create
management/commands/runserver.py
and put in something like this:I was struggling with the same problem and found one solution. I guess it can help you. when you run
python manage.py runserver
, it will take 127.0.0.1 as default ip address and 8000 as default port number which can be configured in your python environment. In your python setting, go to<your python env>\Lib\site-packages\django\core\management\commands\runserver.py
and set 1.default_port = '<your_port>'
2. find this under def handle and set
if not options.get('addrport'): self.addr = '0.0.0.0' self.port = self.default_port
Now if you run "python manage.py runserver" it will run by default on "0.0.0.0:
Enjoy coding .....
In Pycharm you can simply add the port to the parameters
As of Django 1.9, the simplest solution I have found (based on Quentin Stafford-Fraser's solution) is to add a few lines to
manage.py
which dynamically modify the default port number before invoking therunserver
command: