各位老铁们好,相信很多人对django 中文文档都不是特别的了解,因此呢,今天就来为大家分享下关于django 中文文档以及 django的快速入门教程的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!
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 , 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.(现在,您可以在浏览器中输入‘’打开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.
Django入门-如何选择Django版本
选择Django版本时,建议优先选择最新的LTS(长期支持)版本,如当前推荐的3.2版本,因其稳定性高、维护周期长且兼容性较好。以下是具体选择依据和操作建议:
一、优先选择LTS版本的原因长期支持与维护LTS版本(如3.2)通常提供3年以上的官方安全更新和技术支持,适合生产环境使用。非LTS版本可能仅维护18个月左右,后续需频繁升级以避免安全风险。
(图:LTS版本与非LTS版本的支持周期对比)稳定性与兼容性LTS版本经过充分测试,核心功能稳定,且与主流第三方库(如django-rest-framework、channels等)兼容性更好,减少项目开发中的潜在问题。
社区资源丰富LTS版本的文档、教程和问题解决方案更完善,遇到问题时更容易找到参考案例。
二、当前版本推荐Django 3.2(LTS)
发布时间:2021年4月
支持周期:至2024年4月(安全更新)
适用场景:新项目开发、长期维护项目、企业级应用。
(图:Django 3.2版本标识)Django 4.2(最新LTS,2023年发布)若项目启动时间较晚(如2023年后),可考虑直接使用Django 4.2(下一个LTS版本),其支持周期至2026年,且包含更多新特性(如异步视图支持、类型注解优化等)。
三、版本选择的具体建议新项目开发
直接选择最新的LTS版本(如3.2或4.2),平衡稳定性与长期维护需求。
避免使用已停止支持的旧版本(如Django 2.2 LTS已于2022年4月结束支持)。
旧项目升级
若项目基于旧版本(如Django 2.x),建议逐步升级至LTS版本(如3.2),并参考官方升级指南。
升级前需测试兼容性,尤其是自定义中间件、模板标签等核心功能。
学习用途
初学者可选择最新稳定版本(如3.2或4.2),以接触最新特性,但需注意部分第三方库可能未完全适配。
若需参考中文文档,可通过Django官方文档切换语言(如右下角选择zh-hans)。
(图:Django文档语言切换入口)四、版本选择避坑指南避免使用Beta/RC版本非稳定版本(如4.0b1、4.1rc1)可能存在未修复的Bug,仅适合测试环境体验新功能。
注意Python版本兼容性Django版本与Python版本需匹配:
Django 3.2支持Python 3.6~3.9;
Django 4.0+要求Python 3.8+。升级前需确认项目依赖的Python版本是否兼容。
关注第三方库支持部分库(如django-allauth、django-cms)可能对Django版本有严格要求,需提前检查其文档或setup.py中的依赖声明。
五、版本信息查询渠道官方发布说明通过Django Release Notes查看各版本特性、变更和已知问题。支持周期表参考Django官方支持时间表,明确各版本的支持截止日期。
(图:Django官方下载页面,含版本支持信息)总结:对于大多数用户,Django 3.2 LTS是当前最稳妥的选择;若项目允许使用较新版本,可优先考虑Django 4.2 LTS。升级或新建项目时,务必结合Python版本、第三方库兼容性和长期维护需求综合决策。
django为什么不火
Django不火的原因可能有以下几点:
1. Django的中文文档不够完善,这使得在国内使用Django时,学习和配置起来可能会比较困难。
2. Django的活跃贡献者流失,核心团队的作用也在逐渐减弱。这使得Django的更新和维护变得困难,也影响了其在国内的普及和使用。
3. Web技术的演变使得基于PC端的前后端不分离的传统网站的重要性逐渐降低,而Django这种基于MVC开发模式的传统框架在这样的趋势下优势不大。
4.近年来,前后端分离的开发模式越来越流行,而Django在开发符合RESTful规范的Web API时,效率可能并不高。不过,这个问题可以通过使用Django REST Framework这样的工具来改善。
5. Django的适用范围相对较窄,主要适用于基于PC端的大型网站和Web应用开发。而在移动应用开发和其他领域,Django并不具有太大的优势。
综上所述,Django不火的原因主要在于其文档不完善、贡献者流失、开发模式不适应现代Web开发趋势、适用范围较窄等因素。但是,Django仍然有其独特的优势,比如功能完善、稳定性和开发效率高等,因此仍然有一定的市场和使用价值。
专题推荐:
