网页 综合 更新时间 2026-11-14 16:32:05

Django REST framework

自动蜘蛛 www.django-rest-framework.org 正文约 3560 字
Django REST framework is a powerful and flexible toolkit for building Web APIs.
Some reasons you might want to use REST framework:
REST framework requires the following:
We highly recommend and only officially support the latest patch release of each Python and Django series.
The following packages are optional:
Install using pip, including any optional packages you want...
...or clone the project from 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.
Note that the URL path can be whatever you want.
Let's take a look at a quick example of using REST framework to build a simple model-backed API.
We'll create a read-write API for accessing information on the users of our project.
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:
Don't forget to make sure you've also added rest_framework to your INSTALLED_APPS.
We're ready to create our API now. Here's our project's root urls.py module:
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.
Can't wait to get started? The quickstart guide is the fastest way to get up and running, and building APIs with REST framework.
See the Contribution guidelines for information on how to clone the repository, run the test suite and help maintain the code base of REST Framework.
For support please see the REST framework discussion group, try the #restframework channel on irc.libera.chat, or raise a question on Stack Overflow, making sure to include the 'django-rest-framework' tag.
Please report security issues by emailing security@encode.io.
The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.
Copyright © 2011-present, Encode OSS Ltd. 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.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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.
访问原文 返回搜索 https://www.django-rest-framework.org/
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。