Once you have a new Django project set up and understand the basic file structure, you can begin working with the builtin Django development server. The Django development server provides a wonderful local development server that developers can leverage to preview code updates and test features of the Django-powered website. There is no need to worry about configuring a virtual machine, or configuring Docker, though you could go that route if you choose. Many times, the very convenient can capable Django development server will be enough to get up and running with the basics. In this tutorial, we’ll learn a little bit about the local development server in Django.
The built-in development server is part of what the manage.py file offers in any Django Project. To run the development server you’ll want to navigate to the project directory that holds your Django project. This can be done right from Visual Studio code if you like by clicking Terminal-> New Terminal like so.
You’ll notice the new area that shows an integrated terminal right inside of Visual Studio Code where you can type commands.
python manage.py runserver
At the terminal, we can run a special command using the syntax: python manage.py runserver
What this does is use the Python installation on your machine to run the manage.py file from the terminal, while also specifying a sub-command of runserver. The runserver command is a built-in subcommand of Django’s manage.py file that will start up a development server for this specific Django project. Let’s go ahead and run this command now.
myproject $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. June 07, 2021 - 16:43:35 Django version 3.2.4, using settings 'myproject.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
The output in the terminal confirms that an HTTP server is in fact now running on port 8000 for the loopback IP address (127.0.0.1). To confirm this, we can point our web browser to this address and we should see a welcome page for the Django web framework as we see here.
Terminal Debug Feedback
When we use a web browser to make requests to the local development server, we can look at the terminal to see valuable feedback about what is happening in the application. Below we see the output which shows a series of GET requests to render the welcoming Django webpage.
[07/Jun/2021 16:46:26] "GET / HTTP/1.1" 200 10697 [07/Jun/2021 16:46:27] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423 [07/Jun/2021 16:46:27] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184 [07/Jun/2021 16:46:27] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692 Not Found: /favicon.ico [07/Jun/2021 16:46:27] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
New Sqlite File
When running the Django development server for the first time, a new file will be created in the Django project directory with the name of db.sqlite3. This is a new file that holds the database for an SQLite installation. SQLite is a software library that provides a relational database management system that is lightweight in terms of setup, database administration, and required resources. SQLite is self-contained, serverless, has zero configuration, and is transactional. This makes it perfect for building applications locally, and may even be used on smaller-scale production websites. We can see this newly created file in Visual Studio Code.
As we begin working on a new Django Project, we will be able to change the URL in the web browser to preview and test the functionality of those new pages. The development server is an ongoing process and will continue to run until you manually quit the process. To do so, you would need to type CTRL and C at the terminal then press Enter to make the server stop.
Learn More About How To Run Django Development Server
- The Development Server (Official Docs)
- Django Development Environment (developer.mozilla.org)
- Django Server Comparison The Development Server Mod Wsgi Uwsgi And Gunicorn (digitalocean.com)
- How Do You Run A Django Development Server At The Command Prompt (stackoverflow.com)
- How Do You Start The Development Server When Starting A New Django Project (stackoverflow.com)
- Dullhunk Badgr Server (github.com)
- Django Runserver Different Port (koenwoortman.com)