In this tutorial, we aim to explain how to run and manage the Django development server. The Django development server is a lightweight server provided by Django for development purposes. You'll learn how to start, stop, and manage this server, which is crucial to the development and testing of your Django applications.
By the end of this tutorial, you will be able to:
Prerequisites: Basic understanding of Django and Python, and Django installed on your machine.
Django is a high-level Python Web framework that allows rapid development and clean, pragmatic design. It comes with a lightweight server for developing and testing applications. Here's how you can manage this server:
To start the server, navigate to your Django project directory in your terminal and run the following command:
python manage.py runserver
This command starts the server at http://127.0.0.1:8000/
(localhost on port 8000). You can specify a different IP address or port by adding them as arguments to the runserver
command.
To stop the server, you can press CTRL + C
in your terminal where the server is running.
python manage.py runserver 7000
This command will start the server at http://127.0.0.1:7000/
. This is useful when the default port (8000) is being used by another service.
python manage.py runserver 192.168.0.2:8000
This will start the server at http://192.168.0.2:8000/
. This is useful when you want to make your development server accessible from other devices on your network.
Note: Don't use the Django development server in a production setting. It is intended only for development purposes.
In this tutorial, we've covered how to start and stop the Django development server. We've also shown how to run the server on a different IP address and port. These are fundamental skills for developing Django applications.
Next, you might want to learn more about Django's various features and components, such as the Django ORM, Django Templates, and Django Forms.
Additional resources:
- Django Official Documentation
- Django for Beginners
- Django Tutorial on Mozilla Developer Network
Solution:
bash
python manage.py runserver 9000
This command will start the server at http://127.0.0.1:9000/
.
Solution:
Press CTRL + C
in your terminal where the server is running. This command will stop the server.
127.0.0.1
).Solution:
bash
python manage.py runserver 192.168.0.2:8000
This command will start the server at http://192.168.0.2:8000/
.
Remember, practice is key to mastering any skill. Keep experimenting with different commands and options.