Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Projects and Apps  ›  Capstone Project

Running Your Project

Running your Project 12 minpython manage.py runserver starts Django's development server, which reloads on code changes and is meant only for building the site on your own machine.

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

runserver is for building, never for hosting.

From the folder that holds manage.py, with the environment active:

python manage.py runserver
Watching 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 migrate once; the warning goes away and db.sqlite3 now 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.

The cookbook's first runStep 1 of 4
  1. Start it

    python manage.py runserver. One line says to run migrate for 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.

quick drill

Where does runserver serve the site by default?

quick drill

The server warns about unapplied migrations on first run. What fixes it?

quick drill

Why must runserver not host the public cookbook site?

quick drill

You want to run a second project at the same time. Which command avoids the "port already in use" error?

Remember

  • runserver is for building, never for hosting.
  • In the output, find the line that says what to run and the line with the address.
  • Trap: running makemigrations when the warning asks for migrate.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFrom empty folder to rocket page

List every command, in order, from an empty cookbook folder to seeing Django's welcome page in the browser. Then explain the "unapplied migrations" warning the server prints and why runserver must not be used to host the public site.