上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 26 下一页
摘要: argparse模块 argparse是python用于解析命令行参数和选项的标准模块,用于代替已经过时的optparse模块。argparse模块的作用是用于解析命令行参数。 import argparse def get_parameters(): # 创建参数解析对象 parser = arg 阅读全文
posted @ 2021-04-01 18:31 foreast 阅读(113) 评论(0) 推荐(0)
摘要: 函数原型: eval(expression, globals=None, locals=None) 参数: expression:这个参数是一个字符串,python会使用globals字典和locals字典作为全局和局部的命名空间,将expression当做一个python表达式(从技术上讲,是一个 阅读全文
posted @ 2021-04-01 16:15 foreast 阅读(849) 评论(0) 推荐(0)
摘要: address = Address.objects.create( user=request.user, title = receiver, receiver = receiver, province_id = province_id, city_id = city_id, district_id 阅读全文
posted @ 2021-03-29 22:18 foreast 阅读(99) 评论(0) 推荐(0)
摘要: 1. 定义用户地址模型类 1.用户地址模型类 class Address(BaseModel): """用户地址""" user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='addresses', verbose 阅读全文
posted @ 2021-03-29 21:53 foreast 阅读(518) 评论(0) 推荐(1)
摘要: 1.缓存工具 from django.core.cache import cache 存储缓存数据:cache.set('key', 内容, 有效期) 读取缓存数据:cache.get('key') 删除缓存数据:cache.delete('key') 注意:存储进去和读取出来的数据类型相同,所以读 阅读全文
posted @ 2021-03-29 21:37 foreast 阅读(511) 评论(0) 推荐(0)
摘要: itsdangerous的使用 itsdangerous模块的参考资料链接 http://itsdangerous.readthedocs.io/en/latest/ 安装:pip install itsdangerous TimedJSONWebSignatureSerializer的使用 使用T 阅读全文
posted @ 2021-03-28 19:42 foreast 阅读(109) 评论(0) 推荐(0)
摘要: 为了给项目中模型类补充数据创建时间和更新时间两个字段,我们需要定义模型类基类。 在meiduo_mall.utils/models.py文件中创建模型类基类。 from django.db import models class BaseModel(models.Model): """为模型类补充字 阅读全文
posted @ 2021-03-27 17:06 foreast 阅读(117) 评论(0) 推荐(0)
摘要: 多账号登录 Django自带的用户认证后端默认是使用用户名实现用户认证的。 用户认证后端位置:django.contrib.auth.backends.ModelBackend。 如果想实现用户名和手机号都可以认证用户,就需要自定义用户认证后端。 自定义用户认证后端步骤 在users应用中新建uti 阅读全文
posted @ 2021-03-27 15:13 foreast 阅读(421) 评论(0) 推荐(0)
摘要: class LoginView(View): """用户名登录""" def get(self, request): """ 提供登录界面 :param request: 请求对象 :return: 登录界面 """ return render(request, 'login.html') def 阅读全文
posted @ 2021-03-27 14:40 foreast 阅读(478) 评论(0) 推荐(0)
摘要: 1.is_authenticate 判断用户是否登录 介绍: Django用户认证系统提供了方法request.user.is_authenticated()来判断用户是否登录。 如果通过登录验证则返回True。反之,返回False。 缺点:登录验证逻辑很多地方都需要,所以该代码需要重复编码好多次。 阅读全文
posted @ 2021-03-27 14:16 foreast 阅读(1930) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 26 下一页