码迷,mamicode.com
首页 > 其他好文 > 详细

rest framework

时间:2018-05-19 17:10:56      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:sse   patch   strong   isp   set   认证   不同   war   dump   

restful规范

  根据method不同做不同的操作

  url: http://api/user

  method:

    get

    post

    delete

    put

  www.cmdb.com/api/v1/asset?page=2&per_page=100

  

认证

from django.shortcuts import render,HttpResponse

# Create your views here.
from rest_framework.views import APIView
from rest_framework import exceptions
import json

class MyAuthentication(object):
    def authenticate(self,request):
        token = request._request.GET.get(‘token‘)
        if not token:
            raise exceptions.AuthenticationFailed(‘用户认证失败‘)

    def authenticate_header(self,val):
        pass

class Asset(APIView):
    authentication_classes = [MyAuthentication,]
    def get(self,request,*args,**kwargs):
        self.dispatch
        ret = {
            "code":200,
            "msg":"认证成功"
        }
        return HttpResponse(json.dumps(ret))

  

rest framework

标签:sse   patch   strong   isp   set   认证   不同   war   dump   

原文地址:https://www.cnblogs.com/hongpeng0209/p/9060500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!