0
0
Djangoframework~10 mins

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

Choose your learning style9 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.