会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Sch01aR#
三更灯火五更鸡,正是男儿发愤时
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
···
39
下一页
2021年1月16日
DRF - 全局认证
摘要: 在 app 目录下创建 utils 目录,并创建 auth.py auth.py: from rest_framework.authentication import BaseAuthentication # 用于全局认证 class GlobalAuthentication(BaseAuthent
阅读全文
posted @ 2021-01-16 10:59 Sch01aR#
阅读(188)
评论(0)
推荐(0)
2021年1月14日
DRF - 内置认证类
摘要: 在 rest framework 的 authentication.py 中 BaseAuthentication 是我们自己写认证类要继承的 class BaseAuthentication: """ All authentication classes should extend BaseAut
阅读全文
posted @ 2021-01-14 21:45 Sch01aR#
阅读(145)
评论(0)
推荐(0)
2021年1月13日
DRF - 用户登录加 token
摘要: 实现:用户登录成功后,对应的 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#
阅读(410)
评论(0)
推荐(0)
2021年1月12日
DRF - TemplateDoesNotExist,rest_framework/api.html 不存在的解决办法
摘要: 访问一个继承 rest framework APIView 的 url 解决办法: 在 settings.py 中进行配置 添加上这句话就可以解决
阅读全文
posted @ 2021-01-12 23:59 Sch01aR#
阅读(516)
评论(0)
推荐(0)
DRF - 实现一个简单的 token 认证
摘要: rest framework 的 APIView 是继承 django 的 View,且有所扩展 代码: from django.shortcuts import render, HttpResponse from rest_framework.views import APIView # 要被视图
阅读全文
posted @ 2021-01-12 23:55 Sch01aR#
阅读(373)
评论(0)
推荐(0)
Python - 对象列表
摘要: 对象列表即为存放实例化对象的列表 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#
阅读(920)
评论(0)
推荐(0)
2019年9月17日
Python - Django - 扩展默认 auth 表
摘要: 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#
阅读(653)
评论(0)
推荐(0)
2019年9月15日
Python - Django - auth 模块
摘要: 生成数据库 查看 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#
阅读(484)
评论(0)
推荐(0)
2019年9月13日
Python - Django - 中间件 process_template_response
摘要: process_template_response(self, request, response) 有两个参数,response 是 TemplateResponse 对象(由视图函数或者中间件产生) process_template_response 函数是在视图函数执行完后立即执行的 执行 p
阅读全文
posted @ 2019-09-13 17:12 Sch01aR#
阅读(1103)
评论(0)
推荐(0)
Python - Django - 中间件 process_exception
摘要: process_exception(self, request, exception) 函数有两个参数,exception 是视图函数异常产生的 Exception 对象 process_exception 函数的执行顺序是按照 settings.py 中设置的中间件的顺序的倒序执行 process
阅读全文
posted @ 2019-09-13 16:41 Sch01aR#
阅读(1863)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
7
···
39
下一页
公告