01 2021 档案

摘要:django 项目中 __init__.py 的代码为: 运行项目,报错 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.7.11.None. 解决方法: 阅读全文
posted @ 2021-01-22 20:35 Sch01aR# 编辑
摘要:views.py: from rest_framework.viewsets import GenericViewSet from rest_framework import serializers from rest_framework.pagination import PageNumberPa 阅读全文
posted @ 2021-01-21 17:31 Sch01aR# 编辑
摘要:urls.py: from django.urls import path, re_path from drf import views urlpatterns = [ path('render/', views.RenderView.as_view()), ] views.py: from res 阅读全文
posted @ 2021-01-20 22:31 Sch01aR# 编辑
摘要:urls.py: from django.urls import path, re_path from drf import views urlpatterns = [ path('view/', views.TestView.as_view({"get": "list"})), ] views.p 阅读全文
posted @ 2021-01-20 21:08 Sch01aR# 编辑
摘要:GenericAPIView: 源码: class GenericAPIView(views.APIView): queryset = None serializer_class = None lookup_field = 'pk' lookup_url_kwarg = None filter_ba 阅读全文
posted @ 2021-01-20 18:52 Sch01aR# 编辑
摘要:可以在 settings.py 中设置每页显示的数据数量 REST_FRAMEWORK = { "PAGE_SIZE": 2, # 每页显示 2 条内容 } views.py: from rest_framework import serializers from rest_framework.pa 阅读全文
posted @ 2021-01-20 15:57 Sch01aR# 编辑
摘要:可以在 settings.py 中设置每页的大小 REST_FRAMEWORK = { "PAGE_SIZE": 2, # 每页显示 2 条内容 } views.py: from rest_framework import serializers from rest_framework.pagina 阅读全文
posted @ 2021-01-20 15:40 Sch01aR# 编辑
摘要:settings.py 中设置每页的大小 REST_FRAMEWORK = { "PAGE_SIZE": 2, # 每页显示 2 条内容 } view.py: from rest_framework import serializers from rest_framework.pagination 阅读全文
posted @ 2021-01-20 00:20 Sch01aR# 编辑
摘要:views.py: # 自定义规则 class TestValidator(object): def __init__(self, base): self.base = base def __call__(self, value): # 规则明细 if not value.startswith(se 阅读全文
posted @ 2021-01-19 21:16 Sch01aR# 编辑
摘要:views.py: from rest_framework.views import APIView from rest_framework import serializers from django.shortcuts import HttpResponse class UserGroupSer 阅读全文
posted @ 2021-01-19 20:22 Sch01aR# 编辑
摘要:数据库结构和此文章相同:https://www.cnblogs.com/sch01ar/p/14295875.html urls.py: from django.urls import path, re_path from drf import views urlpatterns = [ path( 阅读全文
posted @ 2021-01-19 17:38 Sch01aR# 编辑
摘要:数据库结构和上篇文章一样:https://www.cnblogs.com/sch01ar/p/14295875.html views.py: from rest_framework.views import APIView from rest_framework import serializers 阅读全文
posted @ 2021-01-19 15:36 Sch01aR# 编辑
摘要:models.py: from django.db import models class UserGroup(models.Model): title = models.CharField(max_length=32) class UserInfo(models.Model): user_type 阅读全文
posted @ 2021-01-18 23:53 Sch01aR# 编辑
摘要:model.py: from django.db import models class Role(models.Model): title = models.CharField(max_length=32) 在 role 表中创建数据 方法一:平常的方法 views.py: from drf im 阅读全文
posted @ 2021-01-18 20:40 Sch01aR# 编辑
摘要:https://www.cnblogs.com/sch01ar/p/11271914.html request.POST 的数据是从 request.body 中提取的,request.POST 有数据需要两个前提条件。 一,请求头中 Content-Type 的值为 application/x-w 阅读全文
posted @ 2021-01-18 16:47 Sch01aR# 编辑
摘要:自定义类实现: views.py: from django.shortcuts import HttpResponse from rest_framework.views import APIView from rest_framework.versioning import BaseVersion 阅读全文
posted @ 2021-01-18 15:47 Sch01aR# 编辑
摘要:在 app 目录下的 utils 目录下创建 throttle.py throttle.py: from rest_framework.throttling import SimpleRateThrottle import time # 访问记录 VISIT_RECORD = {} # 用于游客的访 阅读全文
posted @ 2021-01-17 23:32 Sch01aR# 编辑
摘要:在 app 目录下创建 utils 目录,并在该目录下创建 throttle.py throttle.py: from rest_framework.throttling import BaseThrottle import time # 访问记录 VISIT_RECORD = {} class M 阅读全文
posted @ 2021-01-17 15:41 Sch01aR# 编辑
摘要:在 app 目录下创建 utils 目录,并创建 auth.py 和 permission.py 文件 auth.py: from rest_framework.authentication import BaseAuthentication from drf import models from 阅读全文
posted @ 2021-01-16 14:33 Sch01aR# 编辑
摘要:views.py: from django.http import JsonResponse from rest_framework.views import APIView ORDER_DICT = { 1: { "commodity": "Phone", "price": 3600, "date 阅读全文
posted @ 2021-01-16 11:27 Sch01aR# 编辑
摘要:在 app 目录下创建 utils 目录,并创建 auth.py auth.py: from rest_framework.authentication import BaseAuthentication # 用于全局认证 class GlobalAuthentication(BaseAuthent 阅读全文
posted @ 2021-01-16 10:59 Sch01aR# 编辑
摘要:在 rest framework 的 authentication.py 中 BaseAuthentication 是我们自己写认证类要继承的 class BaseAuthentication: """ All authentication classes should extend BaseAut 阅读全文
posted @ 2021-01-14 21:45 Sch01aR# 编辑
摘要:实现:用户登录成功后,对应的 token 表创建一条对应登录用户的 token 数据 models.py: from django.db import models class UserInfo(models.Model): user_type_choices = ( (1, "普通用户"), (2 阅读全文
posted @ 2021-01-13 22:02 Sch01aR# 编辑
摘要:访问一个继承 rest framework APIView 的 url 解决办法: 在 settings.py 中进行配置 添加上这句话就可以解决 阅读全文
posted @ 2021-01-12 23:59 Sch01aR# 编辑
摘要:rest framework 的 APIView 是继承 django 的 View,且有所扩展 代码: from django.shortcuts import render, HttpResponse from rest_framework.views import APIView # 要被视图 阅读全文
posted @ 2021-01-12 23:55 Sch01aR# 编辑
摘要:对象列表即为存放实例化对象的列表 class C1(object): pass class C2(object): pass obj_list = [] # 用于存实例化对象的列表 for func in [C1, C2]: # 遍历类 obj = func() # 生成实例化对象 obj_list 阅读全文
posted @ 2021-01-12 19:43 Sch01aR# 编辑

点击右上角即可分享
微信分享提示