Restarting the Django server displays the following error:
this port is already running....
This problem occurs specifically on Ubuntu and
This is an expansion on Mounir's answer. I've added a bash script that covers this for you. Just run ./scripts/runserver.sh
instead of ./manage.py runserver
and it'll work exactly the same way.
#!/bin/bash
pid=$(ps aux | grep "./manage.py runserver" | grep -v grep | head -1 | xargs | cut -f2 -d" ")
if [[ -n "$pid" ]]; then
kill $pid
fi
fuser -k 8000/tcp
./manage.py runserver
Click the arrow in the screenshot and find the bash with already running Django server. You were getting the message because your server was already running and you tried to start the server again.
if you have face this problem in mac you just need to open activity monitor and force quite python then try again
By default, the runserver command starts the development server on the internal IP at port 8000.
If you want to change the server’s port, pass it as a command-line argument. For instance, this command starts the server on port 8080:
python manage.py runserver 8080
For me, this happens because my API request in Postman is being intercepted by a debugger breakpoint in my app... leaving the request hanging. If I cancel the request in Postman before killing my app's server, the error does not happen in the first place.
--> So try cancelling any open requests you are making in other programs.
On macOS, I have been using sudo lsof -t -i tcp:8000 | xargs kill -9
when I forget to cancel the open http request in order to solve error = That port is already in use.
This also, complete closes my Postman app, which is why my first solution is better.
Click the arrow in the screenshot and find the bash with already running Django server. You were getting the message because your server was already running and you tried to start the server again.