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
.
This is an old post but for those who are interested:
If you want to change the default port number so when you run the "runserver" command you start with your preferred port do this:
DEFAULT_PORT = "8080"
It works with python 2.7 but it should work with newer versions of python as well. Good luck
create a bash script with the following:
save it as runserver in the same dir as manage.py
and run it as
Create a subclass of
django.core.management.commands.runserver.Command
and overwrite thedefault_port
member. Save the file as a management command of your own, e.g. under<app-name>/management/commands/runserver.py
:I'm loading the default port form settings here (which in turn reads other configuration files), but you could just as well read it from some other file directly.
Create enviroment variable in your .bashrc
export RUNSERVER_PORT=8010
Create alias
alias runserver='django-admin runserver $RUNSERVER_PORT'
Im using zsh and virtualenvs wrapper. I put export in projects postactivate script and asign port for every project.
I'm very late to the party here, but if you use an IDE like PyCharm, there's an option in 'Edit Configurations' under the 'Run' menu (Run > Edit Configurations) where you can specify a default port. This of course is relevant only if you are debugging/testing through PyCharm.
If you wish to change the default configurations then follow this steps:
Open terminal type command
Now open runserver.py file in nano editor as superuser
find the 'default_port' variable then you will see the default port no is '8000'. Now you can change it to whatever you want.
Now exit and save the file using "CTRL + X and Y to save the file"
Note: Replace <2/3>.x with your usable version of python