Running the Development Server
The development server runs a Django project so a browser can visit it. The runserver command starts the server.
Start the server
This command starts the server. The server keeps running until CTRL+C, so a test program never starts it.
python manage.py runserverNo addresses yet
This empty list holds no addresses yet. Django shows its welcome page instead.
urlpatterns = []Ask for the home address
The test client asks for / without a server. The number 200 means a page arrived.
client = Client()
print(client.get("/").status_code)Example
import django
from django.conf import settings
settings.configure(DEBUG=True, SECRET_KEY="key", ROOT_URLCONF=__name__, ALLOWED_HOSTS=["*"])
django.setup()
urlpatterns = []
from django.test import Client
client = Client()
print(client.get("/").status_code)Key points
- Use python manage.py runserver to start the development server.
- The address is http://127.0.0.1:8000 when no port is given.
- Stop the server with CTRL+C in the terminal.
- The server prints four startup lines when it starts.
- The test client asks the app for pages with no server running.
In this example, the setup lines configure Django. The empty pattern list holds no addresses yet. The test client asks for / without a server. The number 200 means a page arrived. Django shows its welcome page because no URLs are defined yet. To serve the project to a browser, run python manage.py runserver from the project folder. The server prints Performing system checks... It then prints System check identified no issues (0 silenced). Next it prints Starting WSGI development server at http://127.0.0.1:8000/. Last it prints Quit the server with CONTROL-C.
Note
The development server suits learning, not a public site.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What starts the Django development server?