Introduction
Depending on where and why, you can run the Django server in different ways. For example, we wouldn't run the Django server directly if we were deploying a site to a hosting server or VPS.
Also, to test the server's operation under conditions as close as possible to those experienced when deploying to a live server (DEBUG=False) + (ALLOWED_HOSTS=("localhost",)), you need to use completely different techniques for running the server.
In this article, I'll discuss how to run the Django server in various ways.
Normal server startup for development
This is how the Django server is launched, serving static files and responding to browser requests. By default, it does all this through port 8000, and the command looks like this:
There is only one positional argument, the port number. It can be specified immediately after runserver:
Thus, our server will process only those requests that go to port 7000 and to the local address - http://localhost:7000.
If your Django project is built and configured correctly, but doesn't yet have its own view handlers, you should see something like this:

Or this, if you already have your own views and routing, plus correctly configured STATIC_URL and MEDIA_URL:

The point is all static files are received and served.
Starting the server to check the deployment readiness on the server
What I mean by this is, imagine this: you want to add and configure your own handlers and templates for 404 and 500 pages. But we all know what pages we'll get if we have a server error or a page not found:

And when we put the server into production mode, i.e., DEBUG=False plus ALLOWED_HOSTS=("*"), we'll get a page that we've pre-configured to display 404 and 500 errors, but without styles or scripts. This is what you'll see in the developer console:

The documentation states that when the server switches to production mode, Django stops processing and returning static data. And rightly so, this is the job of a web server like Apache or Nginx.
To continue processing static data while the Django server is running, you need to start the server like this:
Now you can develop your own 400 and 500 pages without having to set up a real server :)
Running a Django server on shared hosting
To run on real web servers, Django doesn't need to be launched manually. For this purpose, every Django application supports special interfaces for working with them. These are:
Setting up Django applications for web servers can vary depending on the hosting provider, but wsgi.py will typically look something like this:
Running a Django server on a VPS
To run a Django server on a VPS, you will need to first configure a web server such as Apache or Nginx so that they can handle requests to the server on a specific port:
Example of configuring an nginx server for the HTTP protocol
Or, more recommended, use port 443, we are living in 2025 after all:
Plus a permanent redirect from port 80:
After that, you need to pass these requests to your Django application. To do this, it must be running. There also needs to be something that can connect web servers (Apache, Nginx) to your application. These are also called web server gateways, like Phusion Passenger or Gunicorn.
Since the server may reboot from time to time, the appropriate daemon/service is created when the server starts/reboots:
This script has substitution variables HOST_PLACE_SETUP and USER_PLACE_SETUP.
This is an example that connects an Nginx web server and a Django application via Gunicorn using unix sockets.
Conclusion
In this article, we looked at four possible ways to launch a Django server.
- The first is a standard development run.
- The second is a production server with static file support, also for development.
- The third is a completely different approach to launching a Django server, using the WSGI and ASGI interfaces.
- And the fourth method describes how to do the same thing, but with greater control and the use of reverse proxies.
If I've missed any special cases or examples that could be added to this article, I'd appreciate your comments and suggestions. ( ̄︶ ̄)↗