Python Web - Werkzeug (WSGI)

Card Puncher Data Processing

About

Werkzeug is a HTTP and WSGI library

request and response objects are provided to work with them.

  • The request data takes the environ object and allows you to access the data from that environ in a nice manner.
  • The response object is a WSGI application in itself and provides a much nicer way to create responses.

Example

  • 1 - the Hello World with response object
from werkzeug.wrappers import Response

def application(environ, start_response):
    response = Response('Hello World!', mimetype='text/plain')
    return response(environ, start_response)
  • 2 - the Hello World with response object and request object that parses the URL to get the query string 'name'
from werkzeug.wrappers import Request, Response

def application(environ, start_response):
    request = Request(environ)
    text = 'Hello %s!' % request.args.get('name', 'World') 
    response = Response(text, mimetype='text/plain')
    return response(environ, start_response)
  • 3 - from the start page
from werkzeug.wrappers import Request, Response

@Request.application
def application(request):
    return Response('Hello World!')

if __name__ == '__main__':
    from werkzeug.serving import run_simple
    run_simple('localhost', 4000, application)

Features

  • debugger
  • Interactive JavaScript based in-browser debugger
  • Basic session and signed cookie support
  • request and response objects,
  • HTTP header parsing and dumping
  • HTTP utilities to handle entity tags,
  • cache control headers,
  • HTTP dates,
  • cookie handling,
  • file uploads,
  • a URL routing system - routing system for matching URLs to endpoints and vice versa
  • and addon modules.





Discover More
Flask Idea Nodebug
Python Web - Flask

Flask is web framework to create web application. The idea of Flask is to build a good foundation for all applications. Everything else is up to you or extensions. Flask is just not designed for large...
Card Puncher Data Processing
Python Web - Web Server Gateway Interface (WSGI)

The Web Server Gateway Interface (WSGI) is a interface that specify how web servers should forward requests to web applications or frameworks. It's written in the Python programming language. A...



Share this page:
Follow us:
Task Runner