Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
119 lines (76 sloc) 2.44 KB

This is a modified version of which attempts to add support for the HTTP 'Accept:' request header.

example code:

def index(request):
    return "Hello, World!\n"

def index(request):
    return '<?xml version="1.0"?><greeting>Hello, World!</greeting>\n'

def index(request):
    return '{ "greeting": "Hello, World!" }\n'

def index(request):
    return "<html><body>Hello, World!</body></html>\n"


$ wget -q -O - --header='Accept: text/plain' http://localhost:8080
Hello, World!

$ wget -q -O - --header='Accept: text/xml' http://localhost:8080
<?xml version="1.0"?><greeting>Hello, World!</greeting>

$ wget -q -O - --header='Accept: application/json' http://localhost:8080
{ "greeting": "Hello, World!" }

$ wget -q -O - --header='Accept: text/html' http://localhost:8080
<html><body>Hello, World!</body></html>

This is just a first stab to flesh out the idea.

Limitations (i.e. things which could be improved upon):

  • You have to define your methods in order from most specific to least specific.
  • Wildcards and 'q' aren't supported yet.

Feel free to take this idea and run with it. Have fun! Jason Pepas

The itty-bitty Python web framework. is a little experiment, an attempt at a Sinatra influenced micro-framework that does just enough to be useful and nothing more.

Currently supports:

  • Routing
  • Basic responses
  • Content-types
  • HTTP Status codes
  • URL Parameters
  • Basic GET/POST/PUT/DELETE support
  • User-definable error handlers
  • Redirect support
  • File uploads
  • Header support
  • Static media serving

Beware! If you're looking for a proven, enterprise-ready framework, you're in the wrong place. But it sure is a lot of fun.


from itty import get, run_itty

def index(request):
    return 'Hello World!'


See examples/ for more usages.

Other Sources

A couple of bits have been borrowed from other sources:


Thanks go out to Matt Croydon & Christian Metts for putting me up to this late at night. The joking around has become reality. :)