转自:https://django-rest-framework.readthedocs.org/en/0.3.1/index.html
Django REST framework
Introduction
Django REST framework is a lightweight REST framework for Django, that aims to make it easy to build well-connected, self-describing RESTful Web APIs.
Browse example APIs created with Django REST framework: The Sandbox
Features:
- Automatically provides an awesome Django admin style browse-able self-documenting API.
- Clean, simple, views for Resources, using Django’s new class based views.
- Support for ModelResources with out-of-the-box default implementations and input validation.
- Pluggable parsers, renderers, authentication and permissions - Easy to customise.
- Content type negotiation using HTTP Accept headers.
- Optional support for forms as input validation.
- Modular architecture - MixIn classes can be used without requiring the Resource or ModelResource classes.
Resources
Project hosting: GitHub.
- The djangorestframework package is available on PyPI.
- We have an active discussion group.
- Bug reports are handled on the issue tracker.
- There is a Jenkins CI server which tracks test status and coverage reporting. (Thanks Marko!)
Any and all questions, thoughts, bug reports and contributions are hugely appreciated.
Requirements
- Python (2.5, 2.6, 2.7 supported)
- Django (1.2, 1.3, 1.4-alpha supported)
Installation
You can install Django REST framework using pip or easy_install:
Or get the latest development version using git:
Or you can download the current release.
Setup
To add Django REST framework to a Django project:
- Ensure that the djangorestframework directory is on your PYTHONPATH.
- Add djangorestframework to your INSTALLED_APPS.
For more information on settings take a look at the Setup section.
Getting Started
Using Django REST framework can be as simple as adding a few lines to your urlconf.
The following example exposes your MyModel model through an api. It will provide two views:
- A view which lists your model instances and simultaniously allows creation of instances from that view.
- Another view which lets you view, update or delete your model instances individually.
urls.py:
How Tos, FAQs & Notes
Examples
There are a few real world web API examples included with Django REST framework.
- Object Store API - Using views.View classes for APIs that do not map to models.
- Code Highlighting API - Using views.View classes with forms for input validation.
- Blog Posts API - Using views.ModelView classes for APIs that map directly to models.
All the examples are freely available for testing in the sandbox:
http://rest.ep.io
(The Sandbox Root API resource is also documented.)