Alibabacloud.com offers a wide variety of articles about django rest framework tutorial, easily find your django rest framework tutorial information here online.
1. SettingsWe created the Django Project tutorial, and the app QuickStart: # Create a new Django Project Django-admin. # Use Virtualenvwrapper to create virtualenv# install Django and Django
Django 1.9 +, and the REST framework will set it for you.
Quickstart
Can't wait to get started? The quickstart guide is the fastest way to get up and running, and building APIs with REST framework.
After talking about a bunch of things, let's get started with a demo and se
Serialization of django-rest-framework,
Preface:I learned about rest-framework serialization yesterday, so I wrote a blog record. Official Website: http://www.django-rest-framework.org/tutoria
Django rest framework requests and responses (detailed description), djangoframework
In the previous article, the specified data is returned when a specified URL is accessed, which also reflects the RESTful API concept. Each URL represents a resource. Of course, we also know that another feature of RESTful APIS is that different request actions will return differ
1. Previously Django-made paging components, when the amount of data is particularly large, performance is not very high, there are three ways to handle:A. Record the last data ID of the current access page, and fetch the number of entriesB. Display up to 120 pagesC. Encrypt page numbers (show previous page, next page only)2.rest Framework PagingFrom rest_framewo
Pagination_class=P2 Third class: Automatically help us to generate four kinds of url,index/$,index/(? p)$ fromRest_framework.routersImportDefaultrouter Router=Defaultrouter () router.register ('Index', views. Indexviewset) Urlpatterns=[url (r'^', include (Router.urls)),]classIndexviewset (viewsets. Modelviewset): Queryset=models. UserInfo.objects.all () Serializer_class=Indexserializer Pagination_class=P2classIndexserializer (serializers. Modelserializer):classMeta:model=models. UserInf
fromApi.serializers.indexImportIndexserializerclassP2 (pagenumberpagination):#number of data bars displayed per pageMax_page_size = 5page_size= 2Page_size_query_param='size' #Page NumberPage_query_param ='page' classIndexview (viewsets. Modelviewset):#you can also not inherit Modelviewset, inherit a few of the above classes, there are only a few methodsQueryset =models. UserInfo.objects.all () Serializer_class=Indexserializer Pagination_class=P2
,'_data'):#调用_parse method Self._data, Self._files=Self._parse ()def_parse (self):#调用 the Select_parser method of the Defaultcontentnegotiation class, see below Parser= Self.negotiator.select_parser (self, self.parsers)#self.parser = configured object list for resolved classes at the time of package request #self.negotiator = self._default_negotiator () = Api_settings. Default_content_negotiation_class () if notparser:#if the return none description does not match, throws
Django rest framework basic introduction and sample code, djangoframework
This article focuses on Django rest framework and shares example as follows.
The Django
Source code Anatomy of the Django REST Framework authentication method
By the Django CBV mode flow, you can know the url匹配完成后,会执行自定义的类中的as_view方法 .
If there is no definition in the custom class as_view方法 , depending on the inheritance of classes in the object-oriented class, you can会执行其父类View中的as_view方法
在
The content of this section
Django Rest Framework Installation
Django Rest framwwork Environment configuration
Simple example Description
Using the rest framework i
currently the relationships in our API are represented by a primary key. in This part of the tutorial, we will improve the cohesion and discovery of the API, rather than using hyperlinks to make relationships. Create an endpoint for the root of our APINow we have the endpoints of ' snippets ' and ' users ', but our API doesn't have an entry point. To create one, we will use a regular function-based view and @api_view The adorner we described earlier
Use Serializermethodfield in the Django REST framework to optimize unnecessary queriesFirst look at an example, in general, for objects that have parent-child relationships, we use the following method to create the class.A article class in which a article object can have multiple comment instances, the class in Django
I. Anomalies
When using the Django Rest framework, if an exception occurs, it is often shown as follows:
{"Detail": "Not allowed."}
But the backstage often wants the common pattern:
{
"desc": "Not allowed.",
"code": +,
"data": null
}
The official website document is very clear, we need to customize exception handling, and then configure it, suc
]
The global settings configuration is as follows:
# Global rest_framework = {"default_permission_classes": ['api. utils. Permission. svippremission'],}
Three built-in Permissions
Django-rest-framework built-in permission basepermission
By default, there is no restriction on permissions.
class BasePermission(object): """ A base class from which all
Simple use of Django REST framework, djangoframework
See https://github.com/linux-wang/DRF_tutorial/blob/master/README.md for details
DRF has a serializer concept. The function is to convert various Django Queryset and model instances to Python native formats, saving the type problems you face when writing APIs, you c
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.