2023年8月9日
摘要: from django.contrib.auth.models import User from django.db.models import Q from django.db.models.functions import Lower from app.models import * 添加操作a 阅读全文
posted @ 2023-08-09 15:53 boye169 阅读(13) 评论(0) 推荐(0) 编辑
摘要: ORM简介 O(objects):类和对象。R(Relation):关系,关系数据库中的表格。M(Mapping):映射。 Django ORM框架的功能: 建立模型类和表之间的对应关系,允许我们通过面向对象的方式来操作数据库。 根据设计的模型类生成数据库中的表格。 通过方便的配置就可以进行数据库的 阅读全文
posted @ 2023-08-09 15:50 boye169 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 模板继承 模板继承和类的继承含义是一样的,主要是为了提高代码重用,减轻开发人员的工作量 {% extends 'base.html' %} base.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> 阅读全文
posted @ 2023-08-09 15:19 boye169 阅读(8) 评论(0) 推荐(0) 编辑
摘要: from django.template import Template,Context,loader def index(context): temp = loader.get_template("table.html") return temp.render(context) def gette 阅读全文
posted @ 2023-08-09 15:01 boye169 阅读(5) 评论(0) 推荐(0) 编辑
摘要: from django.forms.models import model_to_dict Group.objects.get(id=1).__dict__ model_to_dict(Group.objects.get(id=1)) User.objects.get(id=2).to_dict() 阅读全文
posted @ 2023-08-09 14:42 boye169 阅读(35) 评论(0) 推荐(0) 编辑
摘要: https://docs.djangoproject.com/zh-hans/3.1/howto/custom-template-tags/ 代码布局 自定义的 tags 和 filters 会保存在模块名为 templatetags 的目录内。模块文件的名字即稍候你用来加载 tags 的名字,所以 阅读全文
posted @ 2023-08-09 14:28 boye169 阅读(13) 评论(0) 推荐(0) 编辑