会员
周边
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Zeng
Think Twice, Code Once
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
14
15
16
17
18
19
20
21
22
···
24
下一页
2023年12月1日
扩展auth_user表
摘要: 扩展auth_user表 方法一: from django.contrib.auth.models import User # 第一种: 建立一对一外键关系 (不推荐) class UserDetail(models.Model): phone = models.BigIntegerField()
阅读全文
posted @ 2023-12-01 15:40 wellplayed
阅读(76)
评论(0)
推荐(0)
2023年11月30日
Django四件套在响应头中放入数据的方法
摘要: HttpResponse 方法一: return HttpResponse('ok',headers={'xxx':'xxx'}) 方法二: obj = HttpResponse('ok') obj['yyy'] = 'yyy' # 像字典一样放入,最终会放在http的响应头中 return obj
阅读全文
posted @ 2023-11-30 15:19 wellplayed
阅读(41)
评论(0)
推荐(0)
查看一个 '函数' 到底是【函数】还是【方法】
摘要: 需要用到FunctionType和MethodType from types import FunctionType, MethodType 准备测试用代码 写一个函数: def add(): pass 写一个类: class Person: def run(self): pass @classme
阅读全文
posted @ 2023-11-30 15:07 wellplayed
阅读(43)
评论(0)
推荐(0)
2023年11月29日
自定义标签
摘要: 1.在应用(如:app01)下创建文件夹templatetags 再创建一个py文件,编写自定义标签(如:mytag) 2.编写自定义标签 from django import template register = template.Library() @register.filter(name=
阅读全文
posted @ 2023-11-29 21:33 wellplayed
阅读(67)
评论(0)
推荐(0)
页面静态化——Django中Template和Context模块的使用方法
摘要: 1.Template和Context的导入 from django.template import Template, Context 2.生成静态页面 ——在后端调用模板语法生成HTML页面,并保存到指定路径 2.1 我们想生成一个前端页面,代码如下 后端视图层传入的对象: user_data =
阅读全文
posted @ 2023-11-29 20:50 wellplayed
阅读(210)
评论(0)
推荐(0)
绑定给类的方法,对象来调用;与绑定给对象的方法,类来调用的区别
摘要: 绑定给类的方法,类来调用,对象可以调用吗? # 首先创建一个类,和绑定给类的方法index class MyClass: @classmethod def index(cls): print("hello index") 实例化对象: obj = MyClass() 使用对象调用绑定给类的方法: o
阅读全文
posted @ 2023-11-29 17:23 wellplayed
阅读(66)
评论(0)
推荐(0)
CBV源码分析
摘要: 1.路由配置 path('index/', 视图类名.as_view()) # as_view是类的绑定方法 2.执行流程(分析) path('index/', index), >请求来了,路由匹配成功会执行 index(request,) path('index/', UserView.as_vi
阅读全文
posted @ 2023-11-29 15:20 wellplayed
阅读(53)
评论(0)
推荐(0)
JsonResponse源码分析
摘要: 1.视图层返回JsonResponse return JsonResponse({'name':'kevin','age':19}) 2.触发 JsonResponse 的__init__方法 将{'name':'kevin','age':19}传给data 3.源码分析 def __init__(
阅读全文
posted @ 2023-11-29 15:09 wellplayed
阅读(82)
评论(0)
推荐(0)
2023年11月24日
drf高级之——GenericAPIView的使用
摘要: 我们可以使用使用GenericAPIView+序列化类+Response写接口 了解GenericAPIView 类属性: queryset:要序列化的所有数据 serializer_class:序列化类 lookup_field = 'pk' :查询单条时的key值,默认为pk,可以修改名称如'i
阅读全文
posted @ 2023-11-24 09:53 wellplayed
阅读(118)
评论(0)
推荐(0)
物理外键与逻辑外键(on_delete方法)
摘要: 外键中on_delete的方法: CASCADE:级联删除,只要删除publish,跟publish关联的book,全都被删除 SET_DEFAULT:只要删除publish,跟publish关联的book,的publish字段会变成默认值,一定要配合default使用 SET_NULL:只要删除p
阅读全文
posted @ 2023-11-24 09:06 wellplayed
阅读(133)
评论(0)
推荐(0)
上一页
1
···
14
15
16
17
18
19
20
21
22
···
24
下一页
公告