Bird
Raised Fist0
Djangoframework~10 mins

Development server and runserver in Django - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Development server and runserver
Start: Run 'python manage.py runserver'
↓
Django reads settings.py
↓
Setup URL routing and middleware
↓
Start listening on default port 8000
↓
Wait for HTTP requests
↓
Receive request
→Process request through views
↓
Send HTTP response back to browser
↓
Repeat waiting for next request
↓
Stop server on Ctrl+C
The development server starts by running the command, loads settings, listens for requests, processes them, and sends responses until stopped.
Execution Sample
Django
python manage.py runserver
# Server starts on http://127.0.0.1:8000
# Waits for requests
# Processes requests
# Sends responses
# Stops on Ctrl+C
This command starts Django's development server which listens for web requests and serves responses.
Execution Table
StepActionDetailsResult
1Run command'python manage.py runserver'Server process starts
2Load settingsReads settings.py and configures appSettings loaded
3Setup routingConfigures URL patterns and middlewareRouting ready
4Start listeningServer listens on 127.0.0.1:8000Ready to accept requests
5Wait for requestIdle waitingNo requests yet
6Receive requestBrowser sends HTTP GET /Request received
7Process requestRuns matching view functionView returns response
8Send responseHTTP response sent to browserBrowser displays page
9Wait for next requestServer idle againReady for more requests
10Stop serverUser presses Ctrl+CServer stops running
💡 Server stops when user interrupts with Ctrl+C
Variable Tracker
VariableStartAfter Step 4After Step 6After Step 8Final
server_statusNot runningRunningRunningRunningStopped
current_requestNoneNoneGET /NoneNone
response_sentNoNoNoYesYes
Key Moments - 3 Insights
Why does the server keep waiting after sending a response?
Because the development server is designed to handle multiple requests in a row, it waits for the next request after sending a response, as shown in steps 9 and 5 in the execution_table.
What happens if you press Ctrl+C while the server is running?
Pressing Ctrl+C sends an interrupt signal that stops the server process, as shown in step 10 of the execution_table where the server_status changes to 'Stopped'.
Does the development server serve files to the internet?
No, by default it listens only on 127.0.0.1 (localhost), meaning it serves only your computer, not the internet. This is shown in step 4 where the server listens on 127.0.0.1:8000.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the server_status after step 4?
ARunning
BNot running
CStopped
DWaiting for Ctrl+C
💡 Hint
Check variable_tracker column 'After Step 4' for server_status
At which step does the server receive the first HTTP request?
AStep 5
BStep 7
CStep 6
DStep 8
💡 Hint
Look at execution_table row where 'Receive request' action happens
If you stop the server at step 10, what is the current_request value?
AGET /
BNone
CPOST /login
DServer error
💡 Hint
Check variable_tracker 'Final' column for current_request
Concept Snapshot
Run 'python manage.py runserver' to start Django's development server.
Server loads settings, sets up routing, and listens on localhost:8000.
It waits for HTTP requests, processes them with views, and sends responses.
Server keeps running until stopped with Ctrl+C.
Only serves locally by default, not for production use.
Full Transcript
Starting the Django development server involves running the command 'python manage.py runserver'. This command launches a server process that reads the project's settings, sets up URL routing and middleware, and begins listening on the local address 127.0.0.1 at port 8000. The server then waits for HTTP requests from the browser. When a request arrives, it processes the request by running the appropriate view function and sends back an HTTP response. After responding, the server returns to waiting for more requests. This cycle continues until the user stops the server by pressing Ctrl+C, which terminates the process. The development server is designed for local testing and debugging and does not serve requests from the internet by default.

Practice

(1/5)
1. What does the Django runserver command do?
easy
A. Deploys your Django site to the internet permanently
B. Creates a new Django project automatically
C. Starts a simple web server to test your site during development
D. Compiles your Django code into an executable file

Solution

  1. Step 1: Understand the purpose of runserver

    The runserver command is used to start a lightweight web server on your local machine.
  2. Step 2: Identify what runserver is NOT

    It does not deploy your site permanently, create projects, or compile code; it only runs a development server.
  3. Final Answer:

    Starts a simple web server to test your site during development -> Option C
  4. Quick Check:

    runserver = starts local test server [OK]
Hint: Remember runserver means run a local test server [OK]
Common Mistakes:
  • Thinking runserver deploys the site permanently
  • Confusing runserver with project creation commands
  • Assuming runserver compiles code
2. Which of the following is the correct command to start the Django development server on port 8080?
easy
A. python manage.py run 8080
B. python manage.py runserver 8080
C. python manage.py startserver 8080
D. python manage.py runserver -p 8080

Solution

  1. Step 1: Recall the correct syntax for runserver with port

    The correct syntax is python manage.py runserver <port>, so python manage.py runserver 8080 is valid.
  2. Step 2: Identify incorrect options

    Options A, B, and C use wrong flags or commands that do not exist in Django.
  3. Final Answer:

    python manage.py runserver 8080 -> Option B
  4. Quick Check:

    runserver + port number = correct syntax [OK]
Hint: Use runserver followed by port number without flags [OK]
Common Mistakes:
  • Using -p flag which Django does not support
  • Typing startserver instead of runserver
  • Omitting manage.py or using wrong command
3. What will happen if you run python manage.py runserver 0.0.0.0:8000?
medium
A. The server will start and be accessible on all network interfaces
B. The server will start and be accessible only on localhost
C. The command will cause a syntax error
D. The server will start but only on port 80

Solution

  1. Step 1: Understand the IP address 0.0.0.0 in runserver

    Using 0.0.0.0 tells Django to listen on all network interfaces, not just localhost.
  2. Step 2: Confirm the port number usage

    The port 8000 is explicitly set, so the server listens on port 8000 on all interfaces.
  3. Final Answer:

    The server will start and be accessible on all network interfaces -> Option A
  4. Quick Check:

    0.0.0.0 means all interfaces [OK]
Hint: 0.0.0.0 means listen on all network interfaces [OK]
Common Mistakes:
  • Thinking 0.0.0.0 restricts to localhost
  • Assuming port changes to 80 automatically
  • Expecting syntax error from this command
4. You run python manage.py runserver 9000 but get an error saying the port is already in use. What should you do?
medium
A. Choose a different port number and run the command again
B. Restart your computer and run the same command again
C. Change the command to python manage.py runserver --force 9000
D. Uninstall Django and reinstall it

Solution

  1. Step 1: Understand the port in use error

    This error means another program is using port 9000, so Django cannot start the server there.
  2. Step 2: Choose a different port number

    To fix this, pick a free port (like 8000 or 8080) and run python manage.py runserver <new_port>.
  3. Final Answer:

    Choose a different port number and run the command again -> Option A
  4. Quick Check:

    Port in use? Pick another port [OK]
Hint: If port busy, pick another port number [OK]
Common Mistakes:
  • Trying non-existent --force flag
  • Unnecessarily reinstalling Django
  • Assuming restart fixes port conflicts always
5. You want to test your Django site on your phone connected to the same Wi-Fi. Which command lets you run the server so your phone can access it?
hard
A. python manage.py runserver --external 8000
B. python manage.py runserver 127.0.0.1:8000
C. python manage.py runserver localhost:8000
D. python manage.py runserver 0.0.0.0:8000

Solution

  1. Step 1: Understand network accessibility for runserver

    Using 127.0.0.1 or localhost restricts access to your computer only, so other devices cannot connect.
  2. Step 2: Use 0.0.0.0 to allow external devices

    Running python manage.py runserver 0.0.0.0:8000 makes the server listen on all interfaces, allowing your phone on the same Wi-Fi to connect.
  3. Step 3: Identify invalid options

    python manage.py runserver --external 8000 uses a non-existent flag --external, so it will cause an error.
  4. Final Answer:

    python manage.py runserver 0.0.0.0:8000 -> Option D
  5. Quick Check:

    0.0.0.0 allows external access [OK]
Hint: Use 0.0.0.0 to allow devices on your network [OK]
Common Mistakes:
  • Using localhost or 127.0.0.1 which blocks external devices
  • Trying unsupported flags like --external
  • Not connecting phone to same Wi-Fi network
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard