from django.http import HttpResponse from django.shortcuts import render
# Create your views here. from rest_framework.views import APIView from rest_framework.request import Request
class ParamVersion(object): def determin_version(self,request): version = request.query_params.get('version') return version
UsersView class (APIView): DEF GET (Self, Request, * args, ** kwargs): # Request First, start with your own classes to take, if they are not a class, the class went native in the pick , # otherwise it will throw an exception # Version = request._request.GET.get ( 'Version') # Print (Version) # Version = request.query_param.get ( 'Version') # and request._request.GET.get ( 'version') exactly the same as the value of # Print Version return HttpResponse ( 'user list')
Use the built-in class
1 2 3 4 5 6
from rest_framework.versioning import QueryParameterVersioning class UsersView(APIView): versioning_class = QueryParameterVersioning def get(self,request,*args,**kwargs): print(request.version) return HttpResponse('用户列表')
This 3 only needs to be set in the configuration file can be
Returns the version is after packaging request, prior to certification and permission to do
BaseVersioning objects
Which has a rest framework packages reverse (), to generate the reverse url, do not need to specify the version, automatically generated, in fact, the current version of the url, the bottom layer is essentially used Django own reverse () implementation.
Source processes, and similar authentication source,
Matched to url, then in view to view, as_view run a parent () method returns a view function, and the view () function returns Lane dispatch () method, we started from the dispatch () method
First a good package request, and then perform the initial () implementation version and is certified, then the judge's permission, the back is the access frequency
Call determine_version () returns a tuple, there are two elements, respectively, and the processed version of the version of the object
Version is to get in determine_version () method, by versioning_class () method to get to URLPathVersioning object, the default is taken from the configuration file to, and permissions, throttle and other similar processes, but those are to get a list, and needs only to get a version of versioning_class it can also be set to view.