The Development Server

Let’s verify your Django project works. Make sure you are in the outer myclub_site directory and run the following command:

  1. python manage.py runserver

This will start the Django development server—a lightweight Web server written in Python. The development server was created so you can develop things rapidly, without having to deal with configuring a production server until you’re ready for deployment.

When the server starts, Django will output a few messages before telling you that the development server is up and running at http://127.0.0.1:8000/. If you were wondering, 127.0.0.1 is the IP address for localhost, or your local computer. The 8000 on the end is telling you that Django is listening at port 8000 on your local host.

You can change the port number if you want to, but I have never found a good reason to change it, so best to keep it simple and leave it at the default.

Now that the server is running, visit http://127.0.0.1:8000/ with your web browser. You’ll see Django’s default welcome page, complete with a cool animated rocket (Figure 2-6).

It worked!

The Development Server - 图1

Figure 2.6: Django’s welcome page. The welcome page is the same for Django 2 and 3.

TIP: Remember the Startup Sequence

It will help to make a note of this sequence, so you know how to start your Django project each time you return to the examples in this book:

On Windows:

  1. Shift right-click your project folder to open a command window.
  2. Type in env_myclub\scripts\activate to run your virtual environment.
  3. Change into your site directory (cd myclub_site) to run manage.py commands (e.g., runserver).
  4. Type deactivate to exit the virtual environment.

On macOS:

  1. CTRL-click your project folder to open a terminal window.
  2. Type in source env_myclub/bin/activate to run your virtual environment.
  3. Change into your site directory (cd myclub_site) to run manage.py commands (e.g., runserver).
  4. Type deactivate to exit the virtual environment.