The development server lets you see your Django website while you build it. It runs your site on your computer so you can test and fix things easily.
Development server and runserver in Django
python manage.py runserver [optional_port]
You run this command in your project folder where manage.py is located.
If you don't give a port, it uses 8000 by default (like http://127.0.0.1:8000/).
python manage.py runserver
python manage.py runserver 8080python manage.py runserver 0.0.0.0:8000
This command starts the Django development server on your local machine at http://127.0.0.1:8000/. You can open this address in your browser to see your website as you build it.
python manage.py runserver
The development server is for testing only. It is not secure or fast enough for real users.
If you change your code, the server reloads automatically so you see updates right away.
Use CONTROL-C in the terminal to stop the server when you are done.
The runserver command starts a simple web server on your computer.
It helps you see and test your Django site during development.
You can choose the port and make it accessible on your network if needed.
Practice
runserver command do?Solution
Step 1: Understand the purpose of
Therunserverrunservercommand is used to start a lightweight web server on your local machine.Step 2: Identify what
It does not deploy your site permanently, create projects, or compile code; it only runs a development server.runserveris NOTFinal Answer:
Starts a simple web server to test your site during development -> Option CQuick Check:
runserver = starts local test server [OK]
- Thinking runserver deploys the site permanently
- Confusing runserver with project creation commands
- Assuming runserver compiles code
Solution
Step 1: Recall the correct syntax for runserver with port
The correct syntax ispython manage.py runserver <port>, sopython manage.py runserver 8080is valid.Step 2: Identify incorrect options
Options A, B, and C use wrong flags or commands that do not exist in Django.Final Answer:
python manage.py runserver 8080 -> Option BQuick Check:
runserver + port number = correct syntax [OK]
- Using -p flag which Django does not support
- Typing startserver instead of runserver
- Omitting manage.py or using wrong command
python manage.py runserver 0.0.0.0:8000?Solution
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.Step 2: Confirm the port number usage
The port 8000 is explicitly set, so the server listens on port 8000 on all interfaces.Final Answer:
The server will start and be accessible on all network interfaces -> Option AQuick Check:
0.0.0.0 means all interfaces [OK]
- Thinking 0.0.0.0 restricts to localhost
- Assuming port changes to 80 automatically
- Expecting syntax error from this command
python manage.py runserver 9000 but get an error saying the port is already in use. What should you do?Solution
Step 1: Understand the port in use error
This error means another program is using port 9000, so Django cannot start the server there.Step 2: Choose a different port number
To fix this, pick a free port (like 8000 or 8080) and runpython manage.py runserver <new_port>.Final Answer:
Choose a different port number and run the command again -> Option AQuick Check:
Port in use? Pick another port [OK]
- Trying non-existent --force flag
- Unnecessarily reinstalling Django
- Assuming restart fixes port conflicts always
Solution
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.Step 2: Use 0.0.0.0 to allow external devices
Runningpython manage.py runserver 0.0.0.0:8000makes the server listen on all interfaces, allowing your phone on the same Wi-Fi to connect.Step 3: Identify invalid options
python manage.py runserver --external 8000 uses a non-existent flag--external, so it will cause an error.Final Answer:
python manage.py runserver 0.0.0.0:8000 -> Option DQuick Check:
0.0.0.0 allows external access [OK]
- Using localhost or 127.0.0.1 which blocks external devices
- Trying unsupported flags like --external
- Not connecting phone to same Wi-Fi network
Ready to prove it?
Pass the test and this pattern moves unknown
