简体   繁体   English

为什么我可以在调试模式下在同一个 ip 地址和端口上运行多个 django 应用程序?

[英]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.

相关问题 如何在同一端口上运行 Django 应用程序和 Vue? - How can I run a Django app and a Vue on the same port? 我可以在Tornado中获取断开连接的客户端的IP地址和端口吗 - Can I get IP address and port of disconnected client in Tornado 使用 Daphne 在 DEBUG 模式下运行 Django - Run Django in DEBUG mode with Daphne python瓶可以在WINDOWS上的相同地址和端口上运行两个程序 - python bottle can run two programs on the same address and port on WINDOWS 设置Apache以使用虚拟主机在同一域上运行多个django应用 - Setting Apache to run multiple django apps on the same domain with virtual hosts 为什么我不能使用相同的模型注册多个Django ModelAdmin? - Why can't I register multiple Django ModelAdmin with same Model? 我如何在 django 字段中同时允许 IP 地址和 URL? - How can i allow both IP Address and URL in django field? Django 如何登录客户端ip地址? - Django How can I log client ip address? 我如何让django-debug-toolbar只显示在python托管的我的IP地址上的任何地方? - How do I get django-debug-toolbar to only display on my ip address hosted on python anywhere? 同一IP地址上的两个Django项目(服务器) - Two django project on the same ip address (server)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM