重新启动Django服务器会出现以下错误:

this port is already running....

这个问题只发生在Ubuntu上,而不是其他操作系统上。如何释放端口以重新启动服务器?


当前回答

netstat -ntlp

它会像这样。

   Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State           PID/Program name    
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      6599/python         
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      -                   
tcp        0      0 192.168.124.1:53        0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::3306                 :::*                    LISTEN     

所以现在只要关闭Django/python已经运行的端口,杀死与之相关的进程。

kill -9 PID

对我来说

kill -9 6599

现在运行Django应用程序。

其他回答

这是对穆尼尔答案的扩展。我已经为您添加了一个bash脚本。只需运行。/scripts/runserver.sh而不是。/manage.py runserver,它会以完全相同的方式工作。

#!/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

我尝试了所有的解决方案,但它们都不起作用,我建议你继续按下电源按钮,或者如果你的电池是可拆卸的,然后将其移除,所有进程将被杀死,你的本地主机将被重置

不要使用CTRL + Z来停止服务器,使用CTRL + C来停止服务器,我在我的linux (fedora)中也有同样的问题,我曾经使用CTRL + Z停止服务器,再次使用sudo fuser -k 8000/tcp命令杀死服务器,这工作得很好。但后来当我开始使用CTRL + C时,我不再遇到端口运行的问题。

默认情况下,runserver命令在8000端口上启动内部IP上的开发服务器。

如果要更改服务器的端口,请将其作为命令行参数传递。例如,这个命令在端口8080上启动服务器:

python manage.py runserver 8080
ps aux | grep -i manage

after that you will see all process 


ubuntu@ip-10-154-22-113:~/django-apps/projectname$ ps aux | grep -i manage
ubuntu    3439  0.0  2.3  40228 14064 pts/0    T    06:47   0:00 python manage.py runserver project name
ubuntu    3440  1.4  9.7 200996 59324 pts/0    Tl   06:47   2:52 /usr/bin/python manage.py runserver project name
ubuntu    4581  0.0  0.1   7988   892 pts/0    S+   10:02   0:00 grep --color=auto -i manage


kill -9 process id


e.d kill -9 3440


`enter code here`after that :

python manage.py runserver project name