Home > Articles > Programming > Python

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Running the Development Server

At this point, you haven’t built your blog application yet, but nonetheless there are some Django conveniences in place for your use. One of the handiest is Django’s built-in Web server. It’s a server designed not for deploying public sites, but for quick development. Advantages of using it include

  • You don’t need to install Apache, Lighttpd, or whatever other Web server software you’d use in actual production—great if you’re working on a fresh server or a nonserver development machine or just playing around.
  • It automatically detects when you make changes to your Python source files and reloads those modules. This is a huge time-saver compared to manually restarting your Web server every time you edit your code, which is what’s required with most Python Web server setups.
  • It knows how to find and display static media files for the admin application, so you can work with it right away.

Running the development (or “dev”) server is as simple as issuing a single command. We’re going to use our project’s manage.py utility, a thin wrapper script that saves us the work of telling django-admin.py to use our specific project settings file. The command to run the dev server is

./manage.py runserver       # or ".\manage.py runserver" on win32

You should see something like the following with a slight difference for Win32 platforms where the quit key combination is CTRL-BREAK instead of CONTROL-C:

Validating models...
0 errors found.

Django version 1.0, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Open that link in your browser, and you should see Django’s “It Worked!” screen, as shown in Figure 2.2.

Figure 2.2

Figure 2.2 Django’s initial It worked! screen

Meanwhile, if you look in your terminal session, you see the dev server has logged your GET request.

[07/Dec/2007 10:26:37] "GET / HTTP/1.1" 404 2049

The four chunks of the log line are from left to right: timestamp, request, HTTP response code, and byte count. (Your byte count is likely to be slightly different.) The response code is 404 (“Not Found”) because your project has no URLs defined yet. The It Worked! page is Django’s friendly way of telling you that.

When you’ve successfully got the server running, we can move on to setting up your first Django application.

  • + Share This
  • 🔖 Save To Your Account