首页 > 其他 > 详细

rest framework

时间:2018-05-19 16:05:11      阅读:153      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!