1.查看端口占用

C:\>netstat -ano|findstr 8000  
  TCP    0.0.0.0:8000           0.0.0.0:0              LISTENING       8124  
  UDP    0.0.0.0:8000           *:*                                    8124  
  
C:\>tasklist |findstr 8124  
KGService.exe                 8124 Console                    3     14,480 K  
  
C:\Users\liyunzhi>taskkill /pid 8124 /F  
成功: 已终止 PID 为 8124 的进程。  

2. run_django.py 放在项目目录下面

import os
import subprocess
import sys

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def run_shell(shell):
    print(shell)
    cmd = subprocess.Popen(shell, stdin=subprocess.PIPE, stderr=sys.stderr, close_fds=False, stdout=sys.stdout, universal_newlines=True, shell=True, bufsize=1)

    cmd.communicate()
    return cmd.returncode


if __name__ == '__main__':
    test = run_shell("E:\\02-software_python\\01-python\\python.exe {}\\manage.py runserver 0.0.0.0:8000 ".format(path))