As I stated on the title, I'm currently feeling pretty uncomfortable of basic understanding of them.
As far as I know, mod_wsgi implemented WSGI specification which can be run under Apache web server.
It was coded in C language.
Another one, werkzeug is a kind of toolkit which have useful utilities. I also reviewed werkzeug can run simple service which is implemented within its sources(make_server in serving.py). I aware that werkzeug has useful features and simple server feature.
What I want to know it the below.
When using Flask like framework based on werkzeug under Apache web server, what does mod_wsgi do exactly?
werkzeug has also basic http server functionality which is don't need to be supported mod_wsgi.
Can anyone explain the differences between mod_wsgi and werkzeug ?
mod_wsgi and werkzeug has duplicated features from the perspective of web server.
Werkzeug (WSGI library) is like a communicator between your python code and http nginx/apache server Here is the Complete use case of Werkzeug WSGI: WSGI has two sides: the "server" or "gateway" side (often a web server such as Apache or Nginx), and the "application" or "framework" side (the Python script itself).
WSGI has two sides: the "server" or "gateway" side (often a web server such as Apache or Nginx), and the "application" or "framework" side (the Python script itself). To process a WSGI request, the server side executes the application and provides environment information and a callback function to the application side.
What exactly is Werkzeug? Bookmark this question. Show activity on this post. Werkzeug is a WSGI utility library for Python. However, when I run my Flask web application, I notice that the response header from the server contains: On the fourth line the server is mentioning a Werkzeug, but what exactly is Werkzeug, is it a web server like Apache?
To process a WSGI request, the server side executes the application and provides environment information and a callback function to the application side. The application processes the request, returning the response to the server side using the callback function it was provided.
WSGI stands for Web Server Gateway Interface, (mostly) defined by PEP 333 at http://www.python.org/dev/peps/pep-0333/ .
It is an effort by the Python community to establish a standard mechanism for web servers to speak to Python applications.
In theory, any wsgi compliant server (or extension to an existing web server) should be able to load and run any wsgi compliant application.
werkzeug is a web application framework which can run under a compliant WSGI server, such as Apache+mod_wsgi. It also contains a built-in development server that you can use for development.
WSGI can be very confusing at first, but it is actually pretty simple. The WSGI spec requires that your python application do the following:
application
environ
, start_response
)environ
is a dictionary of environment variablesstart_response
is a callable that needs called to start the responseOnce application
is called, then it handles the request, builds the output, and:
start_response('200 OK', Headers)
return [content]
A simple WSGI app might look like this:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
It is strongly suggested that you use an existing WSGI framework, as there are a lot of details involved in parsing HTTP requests, handling file uploads, encoding characters, etc...
Take a look at Bottle, Flask, werkzeug, AppStruct, etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With