##element-ui
/ * Element - UI: based bootstrap on vue hungry it developed bs according page structure characteristics, given the characteristics of the class attribute => EU writing characteristic component tag construct characteristic structure summary: Copy and paste EU: 24 bs: 12 * / # installation: the terminal in the project directory CNPM-UI Element I - S # configure: main.js Import ElementUI from ' Element-UI ' ; Import ' Element-UI / lib / Theme-Chalk / index.css ' ; Vue.use (ElementUI); # use: official API https://element.eleme.cn/ # / zh-CN / the Component / Installation <- - cases!> <EL-Row> <el-button> Default button </ EL-the Button> <EL-Button type = " Primary " > primary button </ EL-Button> <EL-Button type = " Success " > Success button </ EL-Button> <EL-Button type = " info " > Information button </ button-EL> <button EL-type = " warning " > warning button </ EL-button> <button-type EL = " danger " > risk button </ EL-button> </ EL-Row>
## web interfaces
"" " 1, have access to the front desk background url link 2, requests need to pass the required and optional parameters 3, the request to get the desired results returned # Request Tool: Postman => https://www.getpostman.com/ # Interface: url links, to give the corresponding response data through different types of requests to the link data generating # http://127.0.0.1:8888/test/ # https://api.map.baidu.com/place/v2/ Search '' ' AK: 6E823f587c95f0148c19993539b99295 Region: Shanghai query: KFC the Output: json "" "
## Interface Specification: RESTFul specification
# REST: representational state transfer (Representational State Transfer) # RESTful specification: web data request interface design specifications # specification defines two parts: 1, url links should be how to write 2, how to return the data format to write "" " 1) generally use https requests 2) link appears api words https://api.baidu.com https://www.baidu.com/api 3) versions: different versions need to mark - Interface iteration emergence of multi-version coexistence https: // api .baidu.com / V1 https://api.baidu.com/v2 . 4) resource: the resource target data requested call, the resource use single term resource name, resource name multiple resource use plural nouns https: // api .baidu.com / v2 / Book | https://api.baidu.com/v2/books https://api.baidu.com/book | https://api.baidu.com/books 5) request by: error demonstration - get_book | add_book vs correct demonstration - Book https://api.baidu.com/get_book|add_book VS https://api.baidu.com/book Reflect the correct way of operating resources: not by the verb, but by way of request - get: https: //example.com/api/v1/books get all - get: https: //example.com/api / v1 / book / 1 acquires id = 1 a - post: https: //example.com/api/v1/book new one - put: https: //example.com/api/v1/book / update id = 1 a 1 - patch: https: //example.com/api/v1/book/1 an update id = 1 - delete: https: //example.com/api/v1 / book / 1 deleted id = 1 is a 6) resource filter: filter to pass parameters via the interface resources - limit | Ordering | Page - https://example.com/api/v1/books?limit=10 limit 10 Article 7) data status code: return to normal status code data, by the data { "status": 0} - Note: data are agreed status code (not dead) - SUCCESS ( "0", "query success ") - the NODATA (" 1 "," incorrect, no data, display basic information ") - FEAILED (" 2 "," query failed ") 8) error: error message need to mark the request failed - { "error": "error"} => { "msg" : " Data context information"} 9) data (resource operations return results): { "Results": []} | { "Data": []} | { "token": "*"} 10) sub-resources returned resource interface: resource returned if there are sub-resource, returned sub-link address resources, such as finding cover picture book, the book can be expressed url "" "
## drf framework
# Installation and use # 1) mounted DRF: PIP3 the install djangorestframework # 2) register the settings.py App: the INSTALLED_APPS = [..., 'rest_framework'] # . 3) is completed based cbv interface specifications meet RSSTful # view layer # based native django from django.utils.httpwrappers Import jsonResponse from django.views Import View class Book (View): DEF GET (Self, Request, * args, ** kwargs): data_dic = { ' Status ' : 0, ' MSG ' : ' GET OK', 'results': { } } return JsonResponse(data_dic) def post(self, request, *args, **kwargs): data_dic = { 'status': 0, 'msg': 'post ok', 'results': { } } return JsonResponse(data_dic) def delete(self, request, *args, **kwargs): # ... return JsonResponse('', safe=False) # 基于Django REST Framework框架 # drf是django写满足restful规定接口的一个插件 from rest_framework.views import APIView from rest_framework.request import Request from rest_framework.response import Response from rest_framework.viewsets import ViewSet, ModelViewSet from rest_framework.exceptions import APIException from rest_framework.pagination import PageNumberPagination #Custom settings: the settings.py "" " REST_FRAMEWORK = { # custom configuration } " "" # APIView class # as_view (): on a dry matter: csrf_exempt (view) disabled csrf middleware security authentication # dispatch (): # ----- Note dispatch method is to rewrite the parent view's # 1) of the secondary package request object, the original reservation request object to _request wsgi in # 2) the parsed data packet to request.data, parses the data url link to request.query_params? # 3) DRF three certification: certified components, the component authority, frequency components # secondary treatment 4) the response object response in return class the User (APIView): DEF GET (Self, Request, * args, ** kwargs): data_dic = { ' Status ': 0, 'msg': 'get ok', 'results': { } } return Response(data_dic) def post(self, request, *args, **kwargs): a = request.query_params.get('a') x = request.data.get('x') print(a, x) data_dic = { 'status': 0, 'msg': 'post ok', 'results': { } } return Response(data_dic) # 路由层 from app import views urlpatterns = [ url(r'^users/', views.Users.as_view()), ]
## request source code analysis
# As_view () # Core gone parent as_view view = Super (APIView, CLS) .as_view (** initkwargs) # returns to disable local authentication csrf view view function return csrf_exempt (view) # dispatch (Self, Request, args *, ** kwargs) # secondary package request object request = self.initialize_request (request, args *, ** kwargs) # custom request rule self.initial (request, args *, ** kwargs) # initialize_request (self , request, args *, ** kwargs) # original request encapsulated request._request # Initial (Self, request, args *, ** kwargs) # certification self.perform_authentication(request) # 权限 self.check_permissions(request) # 频率 self.check_throttles(request)