Piston, Django REST API 產生器

主站

http://bitbucket.org/jespern/django-piston/

下載

$ hg clone http://bitbucket.org/jespern/django-piston

安裝

$ cd django-piston; sudo python setup.py install

範例

(Django 1.2 為基底)

  1. 建 Project:

    $ django-admin.py startproject mysite
    $ python manage.py startapp api

現在的 tree 像這樣:

.
 ├── __init__.py
 ├── __init__.pyc
 ├── api
 │   ├── __init__.py
 │   ├── models.py
 │   ├── tests.py
 │   └── views.py
 ├── manage.py
 ├── settings.py
 ├── settings.pyc
 └── urls.py
  1. 編輯 mysite/urls.py,加入 API url:

    from django.conf.urls.defaults import *
    
    # Uncomment the next two lines to enable the admin:
    # from django.contrib import admin
    # admin.autodiscover()
    
    urlpatterns = patterns('',
        # Example:
        # (r'^mysite/', include('mysite.foo.urls')),
    
        # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
        # to INSTALLED_APPS to enable admin documentation:
        # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    
        # Uncomment the next line to enable the admin:
        # (r'^admin/', include(admin.site.urls)),
        (r'^api/', include('mysite.api.urls')), # <--- 加入這行
    )
    
  2. 未完待續 ...

API

文件

官方:http://bitbucket.org/jespern/django-piston/wiki/Documentation

加入 OAUTH:http://blog.carduner.net/2010/01/26/django-piston-and-oauth/

簡易計算機:http://www.robertshady.com/content/creating-very-basic-api-using-python-django-and-piston

內容目錄

上一個主題

django notes

下一個主題

Python Cookbook notes

本頁