摘要: sqlite3: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', #'NAME': BASE_DIR / 'db.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlit 阅读全文
posted @ 2022-04-05 20:10 咖喱给给啊 阅读(27) 评论(0) 推荐(0)
摘要: CASCADE:这就是默认的选项,级联删除,你无需显性指定它。 PROTECT: 保护模式,如果采用该选项,删除的时候,会抛出ProtectedError错误。 SET_NULL: 置空模式,删除的时候,外键字段被设置为空,前提就是blank=True, null=True,定义该字段的时候,允许为 阅读全文
posted @ 2022-04-05 19:56 咖喱给给啊 阅读(423) 评论(0) 推荐(0)
摘要: """ 由于django自带的sqlite数据库对日期不敏感,所以我们换成MySQL """ from django.db import models # Create your models here. """ 先写普通字段 之后再写外键字段 """ from django.contrib.aut 阅读全文
posted @ 2022-04-05 19:46 咖喱给给啊 阅读(24) 评论(0) 推荐(0)
摘要: from django.db import models from django.contrib.auth.models import User,AbstractUser # Create your models here. # 第一种:一对一关系 不推荐 # class UserDetail(mo 阅读全文
posted @ 2022-04-05 19:41 咖喱给给啊 阅读(84) 评论(0) 推荐(0)
摘要: from django.shortcuts import render,redirect,HttpResponse from django.contrib import auth # Create your views here. from django.contrib.auth.decorator 阅读全文
posted @ 2022-04-05 19:13 咖喱给给啊 阅读(401) 评论(0) 推荐(0)
摘要: """ 其实我们在创建好一个django项目之后直接执行数据库迁移命令会自动生成很多表 django_session auth_user django在启动之后就可以直接访问admin路由,需要输入用户名和密码,数据参考的就是auth_user表,并且还必须是管理员用户才能进入 创建超级用户(管理员 阅读全文
posted @ 2022-04-05 18:37 咖喱给给啊 阅读(26) 评论(0) 推荐(0)
摘要: from django.views.decorators.csrf import csrf_protect,csrf_exempt from django.utils.decorators import method_decorator """ csrf_protect 需要校验 针对csrf_pr 阅读全文
posted @ 2022-04-05 16:50 咖喱给给啊 阅读(12) 评论(0) 推荐(0)
摘要: 在静态文件夹中建一个js文件 内容: function getCookie(name) { var cookieValue = null; if (document.cookie && document.cookie !== '') { var cookies = document.cookie.s 阅读全文
posted @ 2022-04-05 16:39 咖喱给给啊 阅读(24) 评论(0) 推荐(0)
摘要: 一些细节: 使用process_template_response的时候 需要在视图中这样写,这个东西你自己是想不到的,这个是别人规定好的,不是逻辑问题,是语法问题 def index(request): print('我是视图函数index') obj = HttpResponse('index' 阅读全文
posted @ 2022-04-05 16:18 咖喱给给啊 阅读(19) 评论(0) 推荐(0)
摘要: from django.views import View from django.utils.decorators import method_decorator """ CBV中django不建议你直接给类的方法加装饰器 无论该装饰器能都正常给你 都不建议直接加 """ # @method_de 阅读全文
posted @ 2022-04-05 05:36 咖喱给给啊 阅读(12) 评论(0) 推荐(0)
摘要: """ session数据是保存在服务端的(存?),给客户端返回的是一个随机字符串 sessionid:随机字符串 1.在默认情况下操作session的时候需要django默认的一张django_session表 数据库迁移命令 django会自己创建很多表 django_session就是其中的一 阅读全文
posted @ 2022-04-05 05:35 咖喱给给啊 阅读(78) 评论(0) 推荐(0)
摘要: """ 发展史 1.网站都没有保存用户功能的需求 所有用户访问返回的结果都是一样的 eg:新闻、博客、文章... 2.出现了一些需要保存用户信息的网站 eg:淘宝、支付宝、京东... 以登陆功能为例:如果不保存用户登陆状态 也就意味着用户每次访问网站都需要重复的输入用户名和密码(你觉得这样的网站你还 阅读全文
posted @ 2022-04-05 05:34 咖喱给给啊 阅读(19) 评论(0) 推荐(0)
摘要: # 虽然cookie是服务端告诉客户端浏览器需要保存内容 # 但是客户端浏览器可以选择拒绝保存 如果禁止了 那么 只要是需要记录用户状态的网站登陆功能都无法使用了 # 视图函数的返回值 return HttpResponse() return render() return redirect() o 阅读全文
posted @ 2022-04-05 05:34 咖喱给给啊 阅读(28) 评论(0) 推荐(0)
摘要: ```python label 字段名 error_messages 自定义报错信息 initial 默认值 required 控制字段是否必填 """ 1.字段没有样式 2.针对不同类型的input如何修改 text password date radio checkbox ... """ wid 阅读全文
posted @ 2022-04-05 05:05 咖喱给给啊 阅读(54) 评论(0) 推荐(0)
摘要: """ 在特定的节点自动触发完成响应操作 钩子函数在forms组件中就类似于第二道关卡,能够让我们自定义校验规则 在forms组件中有两类钩子 1.局部钩子 当你需要给单个字段增加校验规则的时候可以使用 2.全局钩子 当你需要给多个字段增加校验规则的时候可以使用 """ # 实际案例 # 1.校验用 阅读全文
posted @ 2022-04-05 05:04 咖喱给给啊 阅读(93) 评论(0) 推荐(0)
摘要: """ 浏览器会自动帮你校验数据 但是前端的校验弱不禁风 如何让浏览器不做校验 <form action="" method="post" novalidate> """ def index(request): # 1 先产生一个空对象 form_obj = MyForm() if request. 阅读全文
posted @ 2022-04-05 05:03 咖喱给给啊 阅读(49) 评论(0) 推荐(0)
摘要: """ forms组件只会自动帮你渲染获取用户输入的标签(input select radio checkbox) 不能帮你渲染提交按钮 """ def index(request): # 1 先产生一个空对象 form_obj = MyForm() # 2 直接将该空对象传递给html页面 ret 阅读全文
posted @ 2022-04-05 05:02 咖喱给给啊 阅读(37) 评论(0) 推荐(0)
摘要: from django import forms class MyForm(forms.Form): # username字符串类型最小3位最大8位 username = forms.CharField(min_length=3,max_length=8) # password字符串类型最小3位最大 阅读全文
posted @ 2022-04-05 05:01 咖喱给给啊 阅读(55) 评论(0) 推荐(0)
摘要: """ 总数据100 每页展示10 需要10 总数据101 每页展示10 需要11 总数据99 每页展示10 需要10 如何通过代码动态的计算出到底需要多少页? 在制作页码个数的时候 一般情况下都是奇数个 符合中国人对称美的标准 """ # 分页 book_list = models.Book.ob 阅读全文
posted @ 2022-04-05 04:48 咖喱给给啊 阅读(83) 评论(0) 推荐(0)
摘要: # 先给Book插入一万条数据 # for i in range(10000): # models.Book.objects.create(title='第%s本书'%i) # # 再将所有的数据查询并展示到前端页面 book_queryset = models.Book.objects.all() 阅读全文
posted @ 2022-04-05 04:47 咖喱给给啊 阅读(89) 评论(0) 推荐(0)