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.
The shortcut
The output is long, but you only hunt for two things: any line that tells you to run something, and the line with the address. The first is your to-do; the second is where to look.
Start it
python manage.py runserver. One line says to runmigratefor 18 unapplied migrations.
Two frequent surprises: "That port is already in use" means another server is still running (stop it or pick a new port), and a syntax error in your code shows up in this terminal, not in the browser.
Drills
Answer fast — trust the rule.
Where does runserver serve the site by default?
The server warns about unapplied migrations on first run. What fixes it?
Why must runserver not host the public cookbook site?
You want to run a second project at the same time. Which command avoids the "port already in use" error?
Remember
runserveris for building, never for hosting.- In the output, find the line that says what to run and the line with the address.
- Trap: running
makemigrationswhen the warning asks formigrate.
