简体   繁体   中英

How to stop the Django development server on windows

I found here answers how to stop the Django Server on Linux but not on windows.

Do I really need to restart my machine?

在您的终端中,垃圾邮件ctrl+c几次。

Open Resource Monitor in the Command Prompt using the command resmon. At the "Listening Ports", find the port you're using. See Resource Monitor here. In my case, is Port 8000. Get the PID, in this example is 20132. Open Task Manager, go to Tab Details, find the PID and end the task. See Task Manager here

For those looking for a programmatic solution, closing port 8000 and all associated connections (there may be more than one) can be done with a .bat script:

@ECHO OFF
SET /A port=8000
FOR /F "tokens=5" %%T IN ('netstat -ano ^| findstr :%port%') DO (
    SET /A processid=%%T
    TASKKILL /PID %%T /F
)

Note that the CMD line netstat -ano ^| findstr :%port% netstat -ano ^| findstr :%port% is used to list the connections using port 8000 :

  >netstat -ano | findstr :8000
  TCP    0.0.0.0:8000           0.0.0.0:0              LISTENING       10920
  TCP    10.0.1.11:8000         10.0.1.11:14813        ESTABLISHED     10920
  TCP    10.0.1.11:8000         10.0.1.11:14814        ESTABLISHED     10920
  TCP    10.0.1.11:8000         10.0.1.11:14815        ESTABLISHED     10920
  TCP    10.0.1.11:14813        10.0.1.11:8000         ESTABLISHED     2628
  TCP    10.0.1.11:14814        10.0.1.11:8000         ESTABLISHED     2628
  TCP    10.0.1.11:14815        10.0.1.11:8000         ESTABLISHED     2628```

Edit1: On windows I used 'Run manage.py Task' in pycharm and I simply closed pycharm and the port is not in use anymore

Edit2: If you are using 'Run manage.py Task' in pycharm, check this: My picture of terminating server There's a in-built option for stopping the server in pycharm

Just Press ctr+C instead of CTRL+BREAK (There is no BREAK key present on keyboard). To fix unapplied migration I wanted to quit server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM