[英]Why can I run multiple django apps on the same ip address and port in debug mode?
I have a question.我有个问题。
When I run a django app, he runs it in localhost: 8000.当我运行 django 应用程序时,他在 localhost:8000 中运行它。
But if I rerun the app, it reruns it in localhost: 8000.但是如果我重新运行该应用程序,它会在 localhost:8000 中重新运行它。
Shouldn't it give error as the server (localhost) with that port (8000) is already busy?它不应该给出错误,因为具有该端口 (8000) 的服务器 (localhost) 已经很忙了吗?
EDIT1: When I say 'rerun the app' I mean this. EDIT1:当我说“重新运行应用程序”时,我的意思是这个。
I executed the 'python manage.py runserver' command first from the vscode terminal and then on the windows terminal.我首先从 vscode 终端执行“python manage.py runserver”命令,然后在 windows 终端上执行。
EDIT2: It only works on the second development server. EDIT2:它只适用于第二个开发服务器。
It is giving an error if you run a second Django development server on the same port.如果您在同一端口上运行第二个 Django 开发服务器,则会出现错误。
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Error: That port is already in use.
But when you say you rerun the app, doesn't that mean that you first close the running development server before you start it up again?但是当你说你重新运行应用程序时,这是否意味着你在再次启动它之前先关闭正在运行的开发服务器? In that case it is of course not an issue.
在那种情况下,这当然不是问题。
I tested this process and found that when two Django projects are executed, the browser will indeed only display the one that runs the development server first, (When we refresh the page, the terminal displays the "development server" that is in use in the log, and ends this process After refreshing the page, another "development server" can be used.), but this does not mean that the default port 8000 is already occupied, " python manage.py runserver
" is to run the development server, and the Django project is indeed deployed to the server.我测试了这个过程,发现当执行两个Django项目时,浏览器确实只会显示第一个运行开发服务器的,(当我们刷新页面时,终端显示正在使用的“开发服务器” log,结束本次流程 刷新页面后,可以使用另一台“开发服务器”),但这并不代表默认的8000端口已经被占用,“
python manage.py runserver
”是运行开发服务器,而Django项目确实部署到了服务器上。
It is recommended that you use a custom port number to avoid the problem of not displaying due to the same port name.建议您使用自定义的端口号,避免因端口名相同导致不显示的问题。 (For example: "
python manage.py runserver 5000
"). (例如:“
python manage.py runserver 5000
”)。
More reference: Django in VSCode .更多参考: Django in VSCode 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.