註意:這是版本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 prehensive 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.