Running Your Project
Everything so far has been files. Now the cookbook comes alive. One command starts a small web server on your own machine, and you can watch every change you make appear in the browser a moment later.
The rule
runserveris for building, never for hosting.
From the folder that holds manage.py, with the environment active:
python manage.py runserverWatching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly
until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Django version 5.2.6, using settings 'cookbook.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
WARNING: This is a development server. Do not use it in a production setting.Open http://127.0.0.1:8000/ and you get Django's welcome page with a rocket. The exact number of migrations may differ; the message is what matters.
Read the output like this:
- Unapplied migrations: the built-in apps (admin, auth, sessions) need tables that do not exist yet. Stop the server and run
python manage.py migrateonce; the warning goes away anddb.sqlite3now holds those tables. - 127.0.0.1:8000: the server listens only on your own machine, on port 8000.
- Control-C stops it.
Useful variations:
python manage.py runserver 8080 # another port
python manage.py runserver 0.0.0.0:8000 # reachable from other devices on your network(For the second, add your computer's address to ALLOWED_HOSTS.)
The development server reloads itself when you save a Python file, so you rarely restart it. But it is built for convenience, not for crowds: it has not been through the security audits or performance work a public server needs. Real deployments run Django behind a production server such as Gunicorn (WSGI) or Uvicorn (ASGI), which use the wsgi.py and asgi.py files startproject made.