Why can I run multiple django apps on the same ip address and port in debug mode?

Viewed 772

I have a question.

When I run a django app, he runs it in localhost: 8000.
But if I rerun the app, it reruns it in localhost: 8000.
Shouldn't it give error as the server (localhost) with that port (8000) is already busy?

EDIT1: When I say 'rerun the app' I mean this.
I executed the 'python manage.py runserver' command first from the vscode terminal and then on the windows terminal.

enter image description here

EDIT2: It only works on the second development server.

enter image description here

2 Answers

It is giving an error if you run a second Django development server on the same port.

Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Error: That port is already in use.

Terminal output showing the error

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.

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").

enter image description here

enter image description here

More reference: Django in VSCode.

Related