Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Python JavaScript HTML CSS
Latest commit 77653d7 @benoitc Merge pull request #14 from mkorenkov/master
Support for Access-Control-Max-Age: 1000 like headers
Failed to load latest commit information.
doc Fixed OptionParser import error.
webmachine Support for Access-Control-Max-Age: 1000 like headers
.gitignore oauth example
LICENSE copyright import webmachine ui for wmtrace .
README.rst Removed django from install_requires.



dj-webmachine is an application layer that adds HTTP semantic awareness on top of Django and provides a simple and clean way to connect that to your applications' behavior. dj-webmachine also offers you the possibility to build simple API based on your model and the tools to create automatically docs and clients from it (work in progress).

dj-webmachine is released under the MIT license. See the LICENSE file for the complete license.

Copyright (c) 2010 Benoit Chesneau <> Copyright 2010 (c) Hyperweek -


Make sure that you have a working Python 2.x >=2.5 installed and Django >= 1.1.

With pip

$ pip install dj-webmachine

From source

Get the dj-webmachine code:

$ git clone
$ cd dj-webmachine

Or using a tarbal:

$ wget -o dj-webmachine.tar.gz
$ tar xvzf dj-webmachine.tar.gz
$ cd dj-webmachine-$HASH/

and install:

$ sudo python install

dj-webmachine in 5 minutes

We will quickly create an Hello world accepting HTML and JSON.

$ django-admin startproject helloworld
$ cd helloworld
$ python startapp hello

In the hello folder create a file named

import json
from webmachine import Resource

class Hello(Resource):

    def content_types_provided(self, req, resp):
        """" define the content type we render accoridng the Accept
        return (
            ("", self.to_html),
            ("application/json", self.to_json)

    def to_html(self, req, resp):
        return "<html><body>Hello world!</body></html>\n"

    def to_json(self, req, resp):
        return "%s\n" % json.dumps({"message": "hello world!", "ok": True})

Add dj-webmachine and your hello app to INSTALLED_APPS in your settings:


Put your the Hello resource in your

from django.conf.urls.defaults import *

from helloworld.hello.resource import Hello

urlpatterns = patterns('',
    (r'^$', Hello()),

Launch your application:

$ python runserver

Take a look! Point a web browser at http://localhost:8000/

Or with curl:

$ curl
<html><body>Hello world!</body></html>

$ curl -H "Accept: application/json"
{"message": "hello world!", "ok": true}

The first line ask the hello page as html while the second using the same url ask for JSON.

To learn how to do more interresting things, checkout some examples or read more documentations .

Something went wrong with that request. Please try again.