视图函数中加上认证功能,流程见下图
import hashlib
import time
def get_random(name):
md = hashlib.md5()
md.update(bytes(str(time.time()),encoding='utf-8'))
md.update(bytes(name,encoding='utf-8'))
return md.hexdigest()
from rest_framework.views import APIView
class Login(APIView):
authentication_classes = [