Django Server Error: port is already in use

前端 未结 16 525
借酒劲吻你
借酒劲吻你 2020-12-04 04:34

Restarting the Django server displays the following error:

this port is already running....

This problem occurs specifically on Ubuntu and

相关标签:
16条回答
  • 2020-12-04 04:53

    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
    
    0 讨论(0)
  • 2020-12-04 04:54

    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.

    0 讨论(0)
  • 2020-12-04 04:56

    if you have face this problem in mac you just need to open activity monitor and force quite python then try again

    0 讨论(0)
  • 2020-12-04 04:58

    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
    
    0 讨论(0)
  • 2020-12-04 04:58

    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.

    0 讨论(0)
  • 2020-12-04 05:00

    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.

    0 讨论(0)
提交回复
热议问题