当前位置: 首页 > news >正文

商城类网站建设报价seo基础教程使用

商城类网站建设报价,seo基础教程使用,成都广告公司网站建设,华强北ic网站建设权限 DRF提供如下几种常见权限: IsAuthenticated, 认证通过 IsAdminUser, 管理员权限 IsAuthenticatedOrReadOnly, 登录用户增删改 非登录用户只能查询 AllowAny,无需认证(默认) 在rest_framework的APIView基础类中&#xf…

权限

DRF提供如下几种常见权限:

IsAuthenticated, 认证通过

IsAdminUser, 管理员权限

IsAuthenticatedOrReadOnly, 登录用户增删改 非登录用户只能查询

AllowAny,无需认证(默认)

在rest_framework的APIView基础类中,对认证与权限做了更高级的封装,如下:

class APIView(View):# The following policies may be set at either globally, or per-view.authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSESpermission_classes = api_settings.DEFAULT_PERMISSION_CLASSES

如果需要单独设置

from django.conf import settings
from rest_framework.authtoken.models import Token
from rest_framework.decorators import api_view,authentication_classes,permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status,generics,viewsets
#from rest_framework import permissions
from rest_framework.authentication import BasicAuthentication,SessionAuthentication,TokenAuthentication
from .models import Course
from .serializers import CourseSerializer
from rest_framework.views import APIView

fbv 方式

##函数式编程
@api_view(['GET','POST'])
@authentication_classes((BasicAuthentication,SessionAuthentication,TokenAuthentication))
@permission_classes((IsAuthenticated,))
def course_list(request):

cbv  gcbv viewsets 方式

# 类视图 Class Based View
class CourseList(APIView):authentication_classes = 
(BasicAuthentication,SessionAuthentication,TokenAuthentication)
permission_classes = ((IsAuthenticated))def get(self,request):print(self.request.user,self.request.auth)

自定义权限

 新建文件permissions.py

from rest_framework import permissionsclass IsOwnerReadOnly(permissions.BasePermission):#只允许对象的所有者能编辑def has_object_permission(self, request, view, obj):"""所有的request 都有读权限:param request::param view::param obj::return:"""#if request.method in ("GET","HEAD","OPTIONS"):if request.method in permissions.SAFE_METHODS:return True#对象的所有这才有写权限return obj.teacher == request.user   #gcbv

加入到views.py 文件

class GCourseDetail(generics.RetrieveUpdateDestroyAPIView):queryset = Course.objects.all()serializer_class = CourseSerializerpermission_classes = (IsAuthenticated,IsOwnerReadOnly)# DRF 视图集 viewsets
class CourseViewSet(viewsets.ModelViewSet):queryset = Course.objects.all()serializer_class = CourseSerializerpermission_classes = (IsAuthenticated, IsOwnerReadOnly)def perform_create(self, serializer):serializer.save(teacher= self.request.user)

http://www.cadmedia.cn/news/5583.html

相关文章:

  • 昆明做网站哪家公司好python培训
  • 管理网站怎么做北京新闻最新消息
  • 商务网站建设与维护试题网站制作多少钱
  • 如何建立一个网站链接的文档青岛seo百科
  • 聊城网站建设策划建设公司宁波搜索引擎优化seo
  • 昆明网站建设技术研发中心解封后中国死了多少人
  • 深圳燃气公司怎么样商丘网站优化公司
  • php网站开发权限管理软文发布平台与板块
  • 做vi的设计公司燃灯seo
  • 网页前端设计包括哪些内容宁波seo排名外包
  • 怎么做一个赚钱得网站培训机构专业
  • 工程建设方案宁波优化seo是什么
  • 成都 网站建设培训学校推广普通话手抄报内容大全资料
  • 营销网站制作皆选ls15227负责网站排行榜前十名
  • 崔各庄地区网站建设超级外链推广
  • 个人怎么报考消防证seo刷关键词排名工具
  • 生产企业解决方案长沙seo外包平台
  • 深圳家居网站建设公司怎样做公司网站推广
  • 昭通市网站建设seo的优点和缺点
  • 淄博网站优化服务手游推广渠道
  • 网站建设的优点和不足seo关键词如何布局
  • 青海高等级公路建设管理局网站提升关键词排名软件哪家好
  • 大学精神文明建设专题网站百度百科合作模式
  • 网站设置不拦截想做网络推广如何去做
  • 家政公司响应式网站建设案例百度收录申请入口
  • 天凡建设股份有限公司网站推广网络广告
  • 网页设计图片居右代码济南优化网络营销
  • 广西教育平台网站建设百度推广培训机构
  • 在局网站 作风建设重庆百度推广排名优化
  • 云南通耀建设工程有限公司网站小红书seo排名帝搜软件