摘要: 1.在应用(如:app01)下创建文件夹templatetags 再创建一个py文件,编写自定义标签(如:mytag) 2.编写自定义标签 from django import template register = template.Library() @register.filter(name= 阅读全文
posted @ 2023-11-29 21:33 wellplayed 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 1.Template和Context的导入 from django.template import Template, Context 2.生成静态页面 ——在后端调用模板语法生成HTML页面,并保存到指定路径 2.1 我们想生成一个前端页面,代码如下 后端视图层传入的对象: user_data = 阅读全文
posted @ 2023-11-29 20:50 wellplayed 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 绑定给类的方法,类来调用,对象可以调用吗? # 首先创建一个类,和绑定给类的方法index class MyClass: @classmethod def index(cls): print("hello index") 实例化对象: obj = MyClass() 使用对象调用绑定给类的方法: o 阅读全文
posted @ 2023-11-29 17:23 wellplayed 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(9) 评论(0) 推荐(0) 编辑
摘要: localhost localhost其实是域名 一般windows系统默认将localhost指向127.0.0.1 但是localhost并不等于127.0.0.1 localhost指向的IP地址是可以配置的(在hosts文件中配置) 127.0.0.1 127开头的IP地址,都是回环地址 实 阅读全文
posted @ 2023-11-29 14:57 wellplayed 阅读(102) 评论(0) 推荐(0) 编辑