随笔分类 - rest framework
摘要:views.py: from rest_framework.viewsets import GenericViewSet from rest_framework import serializers from rest_framework.pagination import PageNumberPa
阅读全文
摘要:urls.py: from django.urls import path, re_path from drf import views urlpatterns = [ path('render/', views.RenderView.as_view()), ] views.py: from res
阅读全文
摘要:urls.py: from django.urls import path, re_path from drf import views urlpatterns = [ path('view/', views.TestView.as_view({"get": "list"})), ] views.p
阅读全文
摘要:GenericAPIView: 源码: class GenericAPIView(views.APIView): queryset = None serializer_class = None lookup_field = 'pk' lookup_url_kwarg = None filter_ba
阅读全文
摘要:可以在 settings.py 中设置每页显示的数据数量 REST_FRAMEWORK = { "PAGE_SIZE": 2, # 每页显示 2 条内容 } views.py: from rest_framework import serializers from rest_framework.pa
阅读全文
摘要:可以在 settings.py 中设置每页的大小 REST_FRAMEWORK = { "PAGE_SIZE": 2, # 每页显示 2 条内容 } views.py: from rest_framework import serializers from rest_framework.pagina
阅读全文
摘要:settings.py 中设置每页的大小 REST_FRAMEWORK = { "PAGE_SIZE": 2, # 每页显示 2 条内容 } view.py: from rest_framework import serializers from rest_framework.pagination
阅读全文
摘要:views.py: # 自定义规则 class TestValidator(object): def __init__(self, base): self.base = base def __call__(self, value): # 规则明细 if not value.startswith(se
阅读全文
摘要:views.py: from rest_framework.views import APIView from rest_framework import serializers from django.shortcuts import HttpResponse class UserGroupSer
阅读全文
摘要:数据库结构和此文章相同:https://www.cnblogs.com/sch01ar/p/14295875.html urls.py: from django.urls import path, re_path from drf import views urlpatterns = [ path(
阅读全文
摘要:数据库结构和上篇文章一样:https://www.cnblogs.com/sch01ar/p/14295875.html views.py: from rest_framework.views import APIView from rest_framework import serializers
阅读全文
摘要:models.py: from django.db import models class UserGroup(models.Model): title = models.CharField(max_length=32) class UserInfo(models.Model): user_type
阅读全文
摘要:model.py: from django.db import models class Role(models.Model): title = models.CharField(max_length=32) 在 role 表中创建数据 方法一:平常的方法 views.py: from drf im
阅读全文
摘要:https://www.cnblogs.com/sch01ar/p/11271914.html request.POST 的数据是从 request.body 中提取的,request.POST 有数据需要两个前提条件。 一,请求头中 Content-Type 的值为 application/x-w
阅读全文
摘要:自定义类实现: views.py: from django.shortcuts import HttpResponse from rest_framework.views import APIView from rest_framework.versioning import BaseVersion
阅读全文
摘要:在 app 目录下的 utils 目录下创建 throttle.py throttle.py: from rest_framework.throttling import SimpleRateThrottle import time # 访问记录 VISIT_RECORD = {} # 用于游客的访
阅读全文
摘要:在 app 目录下创建 utils 目录,并在该目录下创建 throttle.py throttle.py: from rest_framework.throttling import BaseThrottle import time # 访问记录 VISIT_RECORD = {} class M
阅读全文
摘要:在 app 目录下创建 utils 目录,并创建 auth.py 和 permission.py 文件 auth.py: from rest_framework.authentication import BaseAuthentication from drf import models from
阅读全文
摘要:views.py: from django.http import JsonResponse from rest_framework.views import APIView ORDER_DICT = { 1: { "commodity": "Phone", "price": 3600, "date
阅读全文
摘要:在 app 目录下创建 utils 目录,并创建 auth.py auth.py: from rest_framework.authentication import BaseAuthentication # 用于全局认证 class GlobalAuthentication(BaseAuthent
阅读全文