上一页 1 2 3 4 5 6 7 ··· 39 下一页
摘要: 在 app 目录下创建 utils 目录,并创建 auth.py auth.py: from rest_framework.authentication import BaseAuthentication # 用于全局认证 class GlobalAuthentication(BaseAuthent 阅读全文
posted @ 2021-01-16 10:59 Sch01aR# 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 在 rest framework 的 authentication.py 中 BaseAuthentication 是我们自己写认证类要继承的 class BaseAuthentication: """ All authentication classes should extend BaseAut 阅读全文
posted @ 2021-01-14 21:45 Sch01aR# 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 实现:用户登录成功后,对应的 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# 阅读(371) 评论(0) 推荐(0) 编辑
摘要: 访问一个继承 rest framework APIView 的 url 解决办法: 在 settings.py 中进行配置 添加上这句话就可以解决 阅读全文
posted @ 2021-01-12 23:59 Sch01aR# 阅读(465) 评论(0) 推荐(0) 编辑
摘要: rest framework 的 APIView 是继承 django 的 View,且有所扩展 代码: from django.shortcuts import render, HttpResponse from rest_framework.views import APIView # 要被视图 阅读全文
posted @ 2021-01-12 23:55 Sch01aR# 阅读(344) 评论(0) 推荐(0) 编辑
摘要: 对象列表即为存放实例化对象的列表 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# 阅读(896) 评论(0) 推荐(0) 编辑
摘要: models.py: from django.db import models from django.contrib.auth.models import AbstractUser class UserInfo(AbstractUser): phone = models.CharField(max 阅读全文
posted @ 2019-09-17 16:49 Sch01aR# 阅读(636) 评论(0) 推荐(0) 编辑
摘要: 生成数据库 查看 auth_user 数据库 给 auth_user 表创建一个超级用户 邮箱地址可以不写 再看一下 auth_user 表 密码被加密了 login.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 阅读全文
posted @ 2019-09-15 15:39 Sch01aR# 阅读(459) 评论(0) 推荐(0) 编辑
摘要: process_template_response(self, request, response) 有两个参数,response 是 TemplateResponse 对象(由视图函数或者中间件产生) process_template_response 函数是在视图函数执行完后立即执行的 执行 p 阅读全文
posted @ 2019-09-13 17:12 Sch01aR# 阅读(1046) 评论(0) 推荐(0) 编辑
摘要: process_exception(self, request, exception) 函数有两个参数,exception 是视图函数异常产生的 Exception 对象 process_exception 函数的执行顺序是按照 settings.py 中设置的中间件的顺序的倒序执行 process 阅读全文
posted @ 2019-09-13 16:41 Sch01aR# 阅读(1810) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 39 下一页