![]() (If app is a class, this can be accomplished in the _iter_ method.)Ī few other useful middleware ideas: import pprintĭef handle_error (handler ) : def _inner (environ, start_fn ) : try : return handler (environ, start_fn ) except Exception as e : print e # Log error The application returns an iterable containing the bytes in the response body in handy, streamable chunks - in this case, a list of strings containing just "Hello, World!". ![]() The application must call the start_fn with two arguments: the status code (as a string), and a list of headers expressed as 2-tuples.The application callable must accept two arguments: the environ, which is a Python dict containing the request data, and start_fn, itself a callable.A WSGI application is a Python callable, such as a function, a class, or a class instance with a _call_ method. ![]() So what are the essential parts of a WSGI application? Just 3 lines for a running application? That must be some sort of record (barring PHP, because mod_php is cheating). This command tells gunicorn to get the WSGI callable from the app variable in the app module. You can use gunicorn for this just install it via pip ( pip install gunicorn) and run it with gunicorn app:app. Call it app.py and run it with any WSGI-compatible server and you’ll get a Hello World response with a 200 status.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |