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
=request,view=Self ) Ser= Indexserializer (instance=page_user_list,many=True) Ret.data=Ser.data Ret.next=P1.get_next_link () ret.*** =See the source to achieve their ownexceptException as E:ret.code= 1001Ret.error='xxxx Error' returnResponse (ret.__dict__c. Cursor-based paging: Record the ID of the last data, how many entries are taken back, and then encryptclassP3 (cursorpagination): Cursor_query_param='cursor'page_size= 2Ordering='ID' #sorting can also be written-id #usa
,'_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
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
This article mainly introduces the example of implementing the rest request api in python. if you need it, refer to the Sina python api for reference. it is applicable to open-source api requests.
The code is as follows:
#-*-Co
The content of this section
Django Rest Framework Installation
Django Rest framwwork Environment configuration
Simple example Description
Using the rest framework in Django
1.1 Installing the Django rest
token保存到这个用户数据库token_value字段中 Value.save () user_list = [] #取出对象 (query to the user data), this for can not because of the uniqueness of the data, direct index, too lazy to change, in fact, above have already taken, too lazy to change #想把用户名取出来返回出去 for the users in inster_token:name_info= [Users.user_name,users.token_value] User_list.append (name_info) usersinfo=user_l IST[0] # return Dictionary datas = {' status ': ' True ', ' message ': ' Login successful! '
" "keyword argument to%s (). Don ' t do that."% (key, CLS.__name__)) if nothasattr (CLS, key):RaiseTypeError ("%s () received an invalid keyword%r. As_view" "Only accepts arguments that is already" "attributes of the class."% (CLS.__name__, key)) defView (Request, *args, * *Kwargs): self= CLS (* *Initkwargs)ifHasattr (Self,'Get') and notHasattr (Self,'Head'): Self.head=Self.get self.request=
(‘STATUS: ‘ + res.statusCode);equal(200, res.statusCode);console.log(‘HEADERS: ‘ + JSON.stringify(res.headers));res.on(‘data‘,function (chunk) {console.log(‘BODY: ‘ + chunk);});});req.on(‘error‘, function(e) {console.log(‘problem with request: ‘ + e.message);}); req.end();
Save the above code as resttest.js and run it on the command line: node Resttest.js can see the results of the output.The code above simply uses the node's own assert to do unit test and, if interested, introduces a te
Eve is a Python rest API framework. Used to advertise highly customizable, full-featured restful Web services. To help you easily create and deploy APIs, this article is translated from Eve's official site:Http://python-eve.org/quickstart.html#database-interludeEve High Spee
Eve is a Python Rest API framework for publishing highly customizable, full-featured restful Web services that help you easily create and deploy APIs, translated from Eve's official website:Http://python-eve.org/quickstart.html#database-interludeEve Quick Start:Do you want t
Using the ORM in the Python Django framework to establish the query API, djangoorm
Summary
In this article, I will directly discuss the use of Django's low-level ORM query methods from the perspective of anti-pattern. As an alternative, we need to establish query APIs related to specific fields in the model layer that contains business logic. These APIs are not v
Example of using APIs in the Python Bottle framework
This article mainly introduces the example of using APIs in the Python Bottle framework. The author also provides a generated scanner QR code. For more information, see
It is estimated that Otaku is not familiar with this thing. After so many years of development, he
This article mainly introduces the use of the micro-credit API in the Python bottle framework, the author also gives a generated micro-scan two-dimensional code map, the need for friends can refer to the
Micro-letter This thing estimated that otaku few unfamiliar, micro-letter after so many years of development finally to the open platform to make a friendly ste
Example of using API in the Python Bottle framework, pythonbottle
It is estimated that Otaku is not familiar with this thing. After so many years of development, he finally made a friendly step to the open platform. I thought it would have a detailed api and Other interfaces. I was excited to apply for a public platfor
and then resend the document to the API user changes, which can be painful if repeated iterations occur. While there are some API design and documentation tools, such as the Swagger UI, which help developers to write documents more easily, they do not eliminate the complexity inherent in the rest API.
The
of ArcGIS server creates this services Directory when it is initialized.
The entire servicedirectory is based on the rest framework. When using Servicesdirectory, you are guided through a series of links (usually URLs). Whenever you click or use a link, you can see a new page that contains more information about what is available on the server. This information is obtained using URLs through the
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.