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

做ptt网站seo关键词优化软件合作

做ptt网站,seo关键词优化软件合作,做网站需要服务器还是主机,做不锈钢的网站有哪些权限 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.dtcms.com/wzjs/93368.html

相关文章:

  • 怎么制作网站卖电子文件世界军事新闻
  • 做php网站用的软件上海关键词排名搜索
  • 做期货主要看哪个网站东莞寮步最新通知
  • 大连 网站建设 有限公司网站制作的基本流程
  • 网页制作与网站建设课堂实录东莞疫情最新消息今天又封了
  • 重庆网站建设推广公司网站建设营销推广
  • 企业建设网站的方式有两种上海网站排名优化
  • 自己做的网站微信pc端显示乱码百度代发排名
  • 网站seo合同网站统计哪个好用
  • 南宁最高端网站建设网络营销的主要传播渠道是
  • 项目logo生成器橘子seo
  • python做网站 知乎界首网站优化公司
  • 网站制作公司智能 乐云践新宁波seo快速排名
  • 门户网站与搜索引擎的区别雷神代刷推广网站
  • 广告公司企业网站模板百度搜索广告怎么收费
  • 扬州网站建设公元国际seo优化的方法
  • 服务网站建设公司关键词优化公司前十排名
  • 做外贸的网站赚钱吗各大网址收录查询
  • WordPress与dz用户恭喜seo 推广
  • 广州网站建设交易百度广告联盟怎么赚钱
  • 怎样做网站首页的banner微信营销的功能
  • wordpress建站多个域名产品推广计划方案模板
  • 官网网站优化公司百度接单平台
  • 广东知名网站建设seo搜索引擎优化主要做什么
  • 营销型企业网站建设教案个人网页制作教程
  • 建设银行信用卡积分兑换网站百度app安装下载
  • 做网站设计前景怎么样网站seo优化怎么做
  • 淘宝联盟自建网站教程微信营销的模式有哪些
  • 建网站需多少钱拉新推广怎么做代理
  • 南京品牌网站建设seo资源