django rest framework中文介绍
注意局耐:这是版本3的文档。还提供了版本2的文档。
Django REST framework 是一个强大且灵活的工具包,用以构建Web APIs。
为什么要使用REST framework?
REST framework is a collaboratively(合作地) funded project(基金项目). If you use REST framework commercially(商业化的) we strongly(强烈桐滑春) encourage(建议) you to invest(投资) in its continued development(可持续发展) by signing up for a paid plan .(注册付费计划)
Every single(每次简单) sign-up helps us make REST framework long-term financially(财政上) sustainable(财务上可持续发展)
Many thanks to all our wonderful sponsors (赞助商), and in particular to our premium backers(优质的支持者), Rover , Sentry , Stream , Machinalis , and Rollbar .
(非常感谢我们所有的优秀赞助商,特别是我们的优秀支持者, Rover , Sentry , Stream , Machinalis , and Rollbar .
)
REST framework 有以下的要求:
Python (2.7, 3.2, 3.3, 3.4, 3.5,3.6)
Django (1.7+, 1.8, 1.9,,2.0)
下面是可选的包:
Install using pip , including any optional packages you want...(使用pip安装,包括任何你想要的可选包裹...)
...or clone the project from github.(或者从GitHub复制项目)
Add 'rest_framework' to your INSTALLED_APPS setting.
If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root urls.py file.(如果您打算使让销用可浏览的API,您可能还需要添加REST框架的登录和注销视图。将以下内容添加到您的根urls.py文件中。)
Note that the URL path can be whatever you want.(注意,url路径可以是任何你想要的。)
Let's take a look at a quick example of using REST framework to build a simple model-backed API.让我们来看看一个使用REST framework构建一个简单模型支持api的快速示例。
We'll create a read-write API for accessing information on the users of our project.(我们将创建一个读写api,用于访问项目用户的信息。)
Any global settings for a REST framework API are kept in a single configuration dictionary named REST_FRAMEWORK . Start off by adding the following to your settings.py module:(REST framework api的任何全局设置都保存在一个名为“rest_wramework”的配置词典中。首先在“环境”模块中添加以下内容:)
Don't forget to make sure you've also added rest_framework to your INSTALLED_APPS .(别忘了确保你已经在“INSTALLED_APPS”中添加了“rest_framework”。)
We're ready to create our API now. Here's our project's root urls.py module:(我们准备好创建我们的api了。这是我们项目的根源 urls.py 模块:)
You can now open the API in your browser at http://127.0.0.1:8000/ , and view your new 'users' API. If you use the login control in the top right corner you'll also be able to add, create and delete users from the system.(现在,您可以在浏览器中输入‘http://127.0.0.1:8000/’打开api,并查看您的新“用户”api。如果您使用右上角的登录控件,您也可以从系统中添加、创建和删除用户。)
Can't wait to get started? The quickstart guide is the fastest way to get up and running, and building APIs with REST framework.(等不及要开始了?快速启动指南是最快的建立和运行的方式,并建立REST framework的apis。)
The tutorial will walk you through the building blocks that make up REST framework. It'll take a little while to get through, but it'll give you a comprehensive understanding of how everything fits together, and is highly recommended reading.(本教程将帮助您完成组成REST框架的构建块。这需要一点时间来完成,但是它会给你一个全面的理解如何把一切结合起来,并强烈推荐阅读。)
There is a live example API of the finished tutorial API for testing purposes, available here .这里有一个用于测试目的的完成教程API的实例化API,这里可获得
The API guide is your complete reference manual to all the functionality provided by REST framework.(API指南是您对REST框架提供的所有功能的完整参考手册)
General guides to using REST framework.(使用REST框架的一般指南。)
See the Contribution guidelines for information on how to clone the repository, run the test suite and contribute changes back to REST Framework.(有关如何克隆存储库、运行测试套件以及向REST框架贡献更改的信息,请参阅贡献指南。)
For support please see the REST framework discussion group , try the #restframework channel on irc.freenode.net , search the IRC archives , or raise a question on Stack Overflow , making sure to include the 'django-rest-framework' tag.(要获得支持,请参阅REST框架讨论组,在IRC .freenode.net上尝试#restframework通道,搜索IRC档案,或者对Stack Overflow提出问题,确保包含“django-rest-framework”标签。)
For priority support please sign up for a professional or premium sponsorship plan .(如需优先支持,请注册专业或优质赞助计划。)
For updates on REST framework development, you may also want to follow the author on Twitter.(对于REST框架开发的更新,您可能还希望在Twitter上跟随作者。)
Follow @_tomchristie
If you believe you’ve found something in Django REST framework which has security implications, please do not raise the issue in a public forum .
Send a description of the issue via email to rest-framework-security@googlegroups.com . The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.
Copyright (c) 2011-2017, Tom Christie All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.