![Show Menu](styles/mobile-menu.png)
![Page Background](./../common/page-substrates/page0176.png)
If you see a “502 - Bad Gateway”, it’s probably because you forgot to
restart the dev server with
manage.py runserver
after the
migrate
.
Getting to a Production-Ready Deployment
We’re at least reassured that the basic piping works, but we really can’t be using the
Django dev server in production. We also can’t be relying on manually starting it up
with
runserver
.
Switching to Gunicorn
Do you know why the Django mascot is a pony? The story is that Django comes with
so many things you want: an ORM, all sorts of middleware, the admin site … “What
else do you want, a pony?” Well, Gunicorn stands for “Green Unicorn”, which I guess is
what you’d want next if you already had a pony…
elspeth@server:$
../virtualenv/bin/pip install gunicorn
Gunicorn will need to know a path to a WSGI server, which is usually a function called
application
. Django provides one in
superlists/wsgi.py
:
elspeth@server:$
../virtualenv/bin/gunicorn superlists
.wsgi:application2013-05-27 16:22:01 [10592] [INFO] Starting gunicorn 0.18.0
2013-05-27 16:22:01 [10592] [INFO] Listening at: http://127.0.0.1:8000 (10592)
[...]
If you now take a look at the site, you’ll find the CSS is all broken, as in
Figure 8-5.
And if we run the functional tests, you’ll see they confirm that something is wrong. The
test for adding list items passes happily, but the test for layout + styling fails. Good job
tests!
$
python3 manage.py test functional_tests --liveserver=superlists-staging.ottg.eu
[...]
AssertionError: 125.0 != 512 within 3 delta
FAILED (failures=1)
The reason that the CSS is broken is that although the Django dev server will serve static
files magically for you, Gunicorn doesn’t. Now is the time to tell Nginx to do it instead.
148
|
Chapter 8: Testing Deployment Using a Staging Site