Connecting to the real world#
What is WSGI?#
Your Drakken app receives a request for a web page and generates a response. That’s all. It doesn’t know how to communicate with clients such as web browsers; instead it uses an external web server to talk to them. The interface Drakken uses to talk to the web server is called WSGI.
WSGI is pretty simple: you need to provide a callable object (a function or instance with a call method) that expects two parameters:
environ: a dictionary of environmental variables.
start_response: a callback function for sending HTTP status and headers to the server.
That’s it. The
drakken.core module provides Drakken’s WSGI interface.
WSGI web servers#
pip3 install gunicorn
Launch the demo app we created previously:
Visit the demo app’s home page. You should see a web page with the message Hello from the HOME page.
Gunicorn received the request for a web page and sent it to the Drakken demo app. The app generated a response and sent it back to the server which sent it to the client. Communication between server and app was handled through the WSGI protocol.