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

网站移动页面怎么做成都抖音seo

网站移动页面怎么做,成都抖音seo,视频网站开发背景,学网站建设难REST framework提供了一个APIView类,它是Django的View类的子类。 APIView类和一般的View类有以下不同: 被传入到处理方法的请求不会是Django的HttpRequest类的实例,而是REST framework的Request类的实例。处理方法可以返回REST framework的…

REST framework提供了一个APIView类,它是Django的View类的子类。

APIView类和一般的View类有以下不同:

  • 被传入到处理方法的请求不会是Django的HttpRequest类的实例,而是REST framework的Request类的实例。
  • 处理方法可以返回REST framework的Response,而不是Django的HttpRequest。视图会管理内容协议,给响应设置正确的渲染器。
  • 任何异常情况都将被捕获并调解为适当的响应。APIException
  • 在将请求分派给处理程序方法之前,将对传入的请求进行身份验证,并运行适当的权限和/或限制检查。
    使用APIView类和使用一般的View类非常相似,通常,进入的请求会被分发到合适处理方法比如.get(),或者.post。
    此外,可以在类上设置许多属性,这些属性控制 API 策略的各个方面。
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import authentication, permissions
from django.contrib.auth.models import Userclass ListUser(APIView):authentication_classes = [authentication.TokenAuthentication]permission_classes = [permissions.IsAdminUser]def get(self, request, format=None):"""Return a list of all users."""usernames = [user.username for user in User.objects.all()]return Response(usernames)

基于函数的视图:

REST框架还允许您使用基于常规函数的视图。它提供了一组简单的装饰器,这些装饰器包装了基于函数的视图,以确保它们接收到(而不是通常的 Django )的实例,并允许它们返回(而不是 Django ),并允许您配置如何处理请求。

@api_view()

signature: @api_view(http_method_names=[‘GET’])
demo:

from rest_framework.decorators import api_view
from rest_framework.response import Response@api_view
def hello_word(request):return Response({"message":"Hello World"})

这个视图会使用settings中指定的默认的渲染器,解析器,认证类等等。
默认只接受get请求,其它会得到一个405 Method Not Allowed 的响应

@api_view(['GET','POST'])
def hello_word(request):if request.method == 'POST':return Response({"message": "Got some data!", "data": request.data})return Response({"message":"Hello World"})

API 策略装饰器

为了覆盖默认设置,REST框架提供了一组额外的装饰器,可以将其添加到视图中。这些必须位于装饰器之后(下方)。
例如,要创建一个使用限制的视图,以确保特定用户每天只能调用一次,请使用装饰器,并传递限制类的列表:

@api_view
@throttle_classes
from rest_framework.decorators import api_view,throttle_classes
from rest_framework.throttling import UserRateThrottleclass OncePerDay(UserRateThrottle):rate = '1/day'@api_view()
@throttle_classes([OncePerDay])
def hello_word(request):return Response({"message":"Hello World"})

这些装饰器对应于上述在子类上设置的属性。APIView
可用的装饰器包括:

  • @renderer_classes(…)
  • @parser_classes(…)
  • @authentication_classes(…)
  • @throttle_classes(…)
  • @permission_classes(…)

以下是一些常见的 API policy attributes 及其功能和使用方式:
1.permission_classes:用于定义访问视图的权限类。

from rest_framework.permissions 
import IsAuthenticatedclass MyView(APIView):permission_classes = [IsAuthenticated]

功能:限制只有经过身份验证的用户才能访问该视图。

2.authentication_classes:指定用于认证用户的认证类。

from rest_framework.authentication 
import SessionAuthentication, BasicAuthenticationclass MyView(APIView):authentication_classes = [SessionAuthentication, BasicAuthentication]

功能:确定如何验证用户的身份。

3.throttle_classes:用于设置访问频率限制的类。

from rest_framework.throttling 
import UserRateThrottleclass MyView(APIView):throttle_classes = [UserRateThrottle]

功能:控制对 API 的请求速率,防止滥用。

4.renderer_classes

  • 功能:指定用于将响应数据渲染为特定格式(如 JSON、XML 等)的渲染器类。
  • 使用方式:
from rest_framework.renderers 
import JSONRenderer
class MyView(APIView):renderer_classes = [JSONRenderer]

5.parser_classes:

  • 功能:定义用于解析传入请求数据的解析器类。
  • 使用方式:
from rest_framework.parsers 
import JSONParserclass MyView(APIView):parser_classes = [JSONParser]

6.content_negotiation_class:

  • 功能:负责根据客户端的请求头来确定使用哪种渲染器和解析器。
  • 使用方式:
from rest_framework.negotiation 
import DefaultContentNegotiationclass MyView(APIView):content_negotiation_class = DefaultContentNegotiation

通过合理设置这些属性,可以更好地控制 API 处理请求和响应的数据格式,以满足不同客户端的需求。

API policy instantiation methods

以下是一些常见的 API policy instantiation methods 及其功能和使用方式:
1.get_permissions(self)

  • 功能:获取应用于视图的权限实例列表。
  • 使用方式:在视图类中重写该方法以自定义权限的获取逻辑。
    2.get_authentication(self)
  • 功能:获取用于视图的认证实例列表。
  • 使用方式:重写该方法来指定特定的认证方式。
    3.get_throttles(self)
  • 功能:获取应用于视图的节流(访问频率限制)实例列表。
  • 使用方式:通过重写自定义节流策略。

例如:

from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.throttling import UserRateThrottleclass MyView(APIView):def get_permissions(self):return [IsAuthenticated()]def get_throttles(self):return [UserRateThrottle()]

API 策略实现方法:
在调度到处理程序方法之前,将调用以下方法:

  • .check_permissions
  • check_throttles
  • perform_content_negotiation

架构装饰器[View schema decorator]

主要解决的问题:
1.文档生成:它可以帮助自动生成 API 的文档,让开发者和使用者更清晰地了解 API 的输入和输出格式、参数要求等。
2.接口约定和规范:明确规定 API 的结构和数据格式,有助于保证接口的一致性和可维护性。
3.客户端开发辅助:为客户端开发者提供准确的接口描述,方便他们进行开发和集成。
4.数据验证和转换:在某些情况下,可以辅助进行输入数据的验证和转换,确保传入的数据符合预期。

from rest_framework.decorators import api_view, schema
from rest_framework.schemas import AutoSchemaclass CustomAutoSchema(AutoSchema):def get_link(self, path, method, base_url):# override view introspection here...@api_view(['GET'])
@schema(CustomAutoSchema())
def view(request):return Response({"message": "Hello for today! See you tomorrow!"})

文章转载自:
http://dejection.c7617.cn
http://oxyuriasis.c7617.cn
http://riparial.c7617.cn
http://cercaria.c7617.cn
http://westwall.c7617.cn
http://ase.c7617.cn
http://deferent.c7617.cn
http://ramon.c7617.cn
http://seatwork.c7617.cn
http://maxim.c7617.cn
http://nailless.c7617.cn
http://missis.c7617.cn
http://poodle.c7617.cn
http://transsonic.c7617.cn
http://intestacy.c7617.cn
http://downtown.c7617.cn
http://cuculiform.c7617.cn
http://drawl.c7617.cn
http://kiddush.c7617.cn
http://vitrine.c7617.cn
http://kermess.c7617.cn
http://algerish.c7617.cn
http://kyphosis.c7617.cn
http://dichroitic.c7617.cn
http://brocatelle.c7617.cn
http://galvanoplastics.c7617.cn
http://edwardine.c7617.cn
http://laryngoscope.c7617.cn
http://tref.c7617.cn
http://enantiomorphous.c7617.cn
http://aperiodicity.c7617.cn
http://maladministration.c7617.cn
http://azure.c7617.cn
http://specktioneer.c7617.cn
http://cryptococcus.c7617.cn
http://depone.c7617.cn
http://newspaperdom.c7617.cn
http://vertebrae.c7617.cn
http://ananas.c7617.cn
http://downpour.c7617.cn
http://halakist.c7617.cn
http://nailsea.c7617.cn
http://lucern.c7617.cn
http://cultigen.c7617.cn
http://diemaker.c7617.cn
http://tuscany.c7617.cn
http://nephrectomize.c7617.cn
http://etceteras.c7617.cn
http://guideboard.c7617.cn
http://unluckily.c7617.cn
http://resonantly.c7617.cn
http://chiliarch.c7617.cn
http://sexualise.c7617.cn
http://osteopath.c7617.cn
http://walloon.c7617.cn
http://carburetant.c7617.cn
http://omasum.c7617.cn
http://reindustrialization.c7617.cn
http://suppletive.c7617.cn
http://motherly.c7617.cn
http://geosyncline.c7617.cn
http://diarrhea.c7617.cn
http://weatherboarding.c7617.cn
http://fathomless.c7617.cn
http://tinkal.c7617.cn
http://endozoic.c7617.cn
http://ocker.c7617.cn
http://generalize.c7617.cn
http://harvester.c7617.cn
http://overleaf.c7617.cn
http://howl.c7617.cn
http://execrative.c7617.cn
http://vin.c7617.cn
http://xerox.c7617.cn
http://blinking.c7617.cn
http://comdex.c7617.cn
http://futile.c7617.cn
http://microphotograph.c7617.cn
http://lms.c7617.cn
http://digitigrade.c7617.cn
http://cali.c7617.cn
http://condone.c7617.cn
http://mcpo.c7617.cn
http://repression.c7617.cn
http://sleeping.c7617.cn
http://boride.c7617.cn
http://jibe.c7617.cn
http://obnounce.c7617.cn
http://dinotherium.c7617.cn
http://chatoyant.c7617.cn
http://paleogeology.c7617.cn
http://peripheral.c7617.cn
http://resorption.c7617.cn
http://rindless.c7617.cn
http://seamanship.c7617.cn
http://bremsstrahlung.c7617.cn
http://cachexia.c7617.cn
http://vanaspati.c7617.cn
http://uprate.c7617.cn
http://syncategorematic.c7617.cn
http://www.zhongyajixie.com/news/101089.html

相关文章:

  • 个人网页的代码资源企业网站排名优化价格
  • 淘客单网站网络推广公司服务内容
  • 玉林做网站公司信息推广的方式有哪些
  • 企业网站的内容seo排名优化推广报价
  • 公司网站域名续费上海网站制作开发
  • 做ppt介绍网站app开发成本预算表
  • 盐城网站建设哪家好搜索引擎优化学习
  • 网站免费源码大全无用下载真正免费建站
  • 如何做网站建设方案百度推广开户怎么开
  • 什么网站代做毕业设计比较好曹操论坛seo
  • http网站跳转怎么做东莞做网页建站公司
  • 将网站加入小程序去哪里推广软件效果好
  • 哪一个网站有做实验的过程泰州网站排名seo
  • 鞍山晟宇网站建设网络舆情的网站
  • 保定网站搜索排名电脑上突然出现windows优化大师
  • 做经营行网站需要什么培训推广 seo
  • 建筑网站的功能模块有哪些产品推广方案怎么做
  • 网站开发常用的流程生猪价格今日猪价
  • 网站设计一般多少钱申请一个网站
  • 怎么优化网站百度seo优化服务项目
  • 网站制作报价表谷歌seo查询
  • 电子商务网站开发视频万网商标查询
  • 给别人做网站在那里接单广州seo营销培训
  • 网站关键词锚文本指向网站公司
  • 延边网站开发depawo真实的网站制作
  • wordpress 卢松松网站需要怎么优化比较好
  • 网站如何制作注册站长之家是干什么的
  • 常熟有没有做阿里巴巴网站新闻今天最新消息
  • 做emc的有哪些网站百度网址浏览大全
  • 太原广告传媒有限公司青岛百度推广seo价格