views中

from rest_framework.views import APIView
from django.shortcuts import HttpResponse from api.utils.auth_class import LoginAuth
from api.models import * from django.core.exceptions import ObjectDoesNotExist from api.utils.response import BaseResponse
import json from rest_framework.response import Response
from django.http import JsonResponse from api.utils.exceptions import PriceException from django_redis import get_redis_connection class ShoppingCarView(APIView): authentication_classes = [LoginAuth,]
response=BaseResponse()
conn=get_redis_connection("default")def post(self,request):
def post(self,request):
"""
购物车的添加课程请求
:param request:
:return:
"""
.....
def get(self,request):
"""
查看购物车列表请求
:param request:
:return:
"""
pass
自定义认证  from api.utils.auth_class import LoginAuth,api是自定义组件(相当于app01)
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
from api.models import UserToken class LoginAuth(BaseAuthentication): def authenticate(self, request): #一定要重写该方法
token=request.GET.get("token")
token_obj=UserToken.objects.filter(token=token).first() if token_obj:
return token_obj.user,token_obj.token
else:
raise AuthenticationFailed("认证失败了")
自定义异常处理  from api.utils.exceptions import PriceException
class PriceException(Exception):

    def __init__(self):
self.msg="价格策略有问题,你不是人!"
自定义 response      from api.utils.response import BaseResponse
class BaseResponse(object):

    def __init__(self):
self.data=None
self.error_msg=""
self.code=1000 @property
def dict(self): return self.__dict__

最新文章

  1. 团队作业week9 scenario testing
  2. thinkphp nginx php-fpm url rewrite 导致 404 错误
  3. C#中线程对控件的访问
  4. Hadoop SPARK 环境搭建
  5. background-attachment:fixed应用
  6. 老鸟的Python新手教程
  7. jQuery中的DOM操作总结
  8. vue组件利用formdata图片预览以及上传《转载》
  9. scala的安装及使用
  10. 006.SMB之用户管理
  11. Kong安装简介
  12. Yii1.1测试环境配置(一)
  13. NodeJs -- express 快速建站
  14. Java NIO使用及原理分析(二)(转)
  15. C#缓存-依赖 CacheHelper
  16. [Codefroces401D]Roman and Numbers(状压+数位DP)
  17. 【.Net】Socket小示例
  18. IOS开发学习笔记042-UITableView总结2
  19. token验证机制
  20. vs2015终于配置完成了

热门文章

  1. iOS 如何监听用户在手机设置里改变了系统的时间?
  2. 降维处理PCA
  3. 《PHP面试笔试真题库》——PHP面试的好帮手
  4. 我是如何破解你的WINDOWS密码的 ?(2)
  5. Vue 源码解读(1)—— 前言
  6. 显式锁之ReentrantLock实现
  7. 为什么使用Mybatis对JDBC进行包装探究
  8. CSS代码示例-背景属性(background)
  9. 从.net开发做到云原生运维(零)——序
  10. c++动态内存管理与智能指针