Run Server
Django provides an easy-to-launch development server used for testing during app development processes. When you run the runserver
command, your app is deployed in the local environment. The launched server listens on port 8000. You can access the launched app by typing localhost:8000 in your web browser.
The runserver command
You can launch your app in your local environment quickly by running the runserver command.
We haven't developed any code yet, but you can check how the runserver command works by running the command below. The manage.py file is used to call the runserver command.
python manage.py runserver
When you run the command above, you'll see the message below.
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.
March 13, 2023 - 11:30:31
Django version 4.1.7, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
First, you'll notice that there is an alert saying there are unapplied migrations. This means that pre-designed databases are not implemented yet. For now, you can ignore this message. We'll explain this later.
Accessing the launched Django app
If you look at the latter part of the message in the command line above, you can see "Starting development server at http://127.0.0.1:8000/. This means that your Django app is accessible at the IP address and port. 127.0.0.1 is a loopback IP address that is also called localhost. This address is pointing to your computer.
By typing "localhost:8000" in your web browser address bar, you'll see that the Django app is now running.
Quit the server
As the server is running as a foreground process, you need to use keyboard shortcut (Ctrl + C) to quit the server.
Tips: Python command when venv is activated
When venv is activated, you can run a Python command by simply typing 'python
' even on Mac or Linux. No need to type 'python3
' as the command line already recognizes the Python being used is Python 3.