Django REST framework¶
2012-05-07 10:25
239 查看
Django REST framework
Browse example APIs created with Django REST framework: The Sandbox
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.
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.
Django (1.2, 1.3, 1.4 supported)
django.contrib.staticfiles (or django-staticfiles for Django 1.2)
URLObject >= 2.0.0
Markdown >= 2.1.0 (Optional)
PyYAML >= 3.10 (Optional)
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.
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:
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 supported)
django.contrib.staticfiles (or django-staticfiles for Django 1.2)
URLObject >= 2.0.0
Markdown >= 2.1.0 (Optional)
PyYAML >= 3.10 (Optional)
Installation¶
You can install Django REST framework using pip or easy_install:pip install djangorestframeworkOr get the latest development version using git:
git clone git@github.com:tomchristie/django-rest-framework.git
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.
from django.conf.urls.defaults import patterns, url from djangorestframework.resources import ModelResource from djangorestframework.views import ListOrCreateModelView, InstanceModelView from myapp.models import MyModel class MyResource(ModelResource): model = MyModel urlpatterns = patterns('', url(r'^, ListOrCreateModelView.as_view(resource=MyResource)), url(r'^(?P<pk>[^/]+)/ , InstanceModelView.as_view(resource=MyResource)), )
相关文章推荐
- 利用 Django REST framework 编写 RESTful API
- Django rest framework(5)----解析器
- Django Rest Framework源码剖析(八)-----视图与路由
- django Rest Framework 系列 1 - 序列化 Serialization
- django rest framework 入门1-序列化 Serialization
- Django REST framework的各种技巧——3.权限
- Django REST Framework 学习笔记
- Django Rest Framework 教程及API向导
- Django REST FrameWork中文教程2:请求和响应
- Django REST framework 源码剖析
- Django REST framework教程二: 请求和响应
- django rest framework--quickstart[中文文档]
- django Rest Framework---缓存通过drf-extensions扩展来实现
- Django REST framework
- 基于 Django REST framework 3.6.2 文档的学习(1)—— 基本介绍
- python Django rest framework
- django rest framework通用view
- 阿里云Ubuntu 16.04部署Python Django REST framework
- Django REST framework-API指南05-ViewSets 原创翻译
- Django Rest Framework(Response)