Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Using Django's WSGIServer in Development

For more on httpie, check out the documentation.

00:00 Using Django’s WSGIServer in Development. In this section, you’ll test Django’s development server using httpie, a command-line HTTP client for testing requests to your web app from the console.

00:15 First, use cd to change back to the home directory, then pwd to check the absolute location of it. Check that you are using the correct virtual environment and install httpie.

00:41 You can create an alias that will let you send a GET request using httpie to your application. This aliases GET to an http call with some default flags.

00:53 You can now use GET docs.python.org to see the response headers and body from the Python documentation’s home page. Before starting the Django development server, you can check your Django project for potential problems.

01:17 If your check doesn’t identify any issues, then tell Django’s built-in application server to start listening on localhost, using the default port of 8000.

01:29 Using nohup <command> & executes the command in the background so that you can continue to use your shell. nohup will redirect standard output and standard error to the file nohup.out. If it appears that nohup hangs and leaves you without a cursor, press Enter to get your terminal cursor and shell prompt back.

01:50 You can use the jobs command to see the process identifier, which will let you bring the process to the foreground or terminate it. Django’s runserver command uses the syntax seen on-screen.

02:05 If you leave the address:port argument unspecified as seen previously, Django will default to listening on localhost port 8000. You can use the lsof command to verify more directly that a python command was invoked to listen on port 8000.

02:28 At this point in the course, your app is only listening on localhost, which is the address It’s not yet accessible from a browser, but you can still give it its first visitor by sending a GET request from the command line within the VM itself.

02:50 The header section seen on-screen describes the software that generated the response. In this case, it’s version 0.2 of WSGIServer alongside CPython 3.10.

03:05 WSGIServer is nothing more than a Python class defined by Django that implements the Python WSGI protocol. What this means is that it adheres to the Web Server Gateway Interface (WSGI), which is a standard that defines a way for web server software and web applications to interact.

03:25 In our example so far, the django-gunicorn-nginx/ project is the web application. Since you’re serving the app in development, there’s actually no separate web server. Django uses the simple_server module, which implements a lightweight HTTP server, and fuses the concept of web server versus application server into one command, runserver.

03:49 In the next section of the course, you’ll see how to get your site online for the world to see.

Become a Member to join the conversation.