![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
悄悄的
这个作者很懒,什么都没留下…
展开
-
django中的分组聚合orm
比如我们有这样两个model, 一个代表作业,一个代表作业发布的班级。HomeworkClass 表有外键homework_id关联Homework。https://docs.djangoproject.com/zh-hans/2.2/topics/db/aggregation/from django.db import modelsclass Homework(models.Model): id = models.BigIntegerField(primary_key=True) u原创 2020-09-10 11:11:46 · 1020 阅读 · 0 评论 -
Django signals
django的信号主要体现了一种观察者模式一、观察者模式(这段代码是抄的)class Asensor: # 创建一个观察者,当被观察者到达某种状态时,或者代码运行带某处时触发观察者 @classmethod def update(self): print('this is A')class Bsensor: # 创建一个观察者,当被观...原创 2019-08-30 17:06:44 · 168 阅读 · 0 评论 -
async await
await 表示函数可以停止运行,等待await 内的函数完成后继续运行函数,而不是await等待,函数继续运行。async def yyy(): time.sleep(1)async def www(): time.sleep(2)async def xxx(): await yyy() await www() print('xxx')运行xxx函数不能通过直接调用的方式...原创 2019-05-24 17:30:46 · 237 阅读 · 0 评论 -
运行django时出现python 停止工作的问题。
django 项目从mac移动到windows上,运行时出现python 停止工作的问题。不知为什么就想到了可能是mysql数据库的问题。发现自己在windows上新装的mysql。为了简单就没有设置密码。所以报错。设置密码后就好了。mysql 高版设置密码(不知道从哪个版本开始)"ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_na...原创 2019-03-30 10:39:16 · 1576 阅读 · 0 评论 -
自己添加一个Templates
今天建了一个Django项目,发现没有templates,于是自己建了一个,要想让他好用需要配置如下TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR,'templates')], #在这...原创 2019-03-13 16:11:49 · 237 阅读 · 0 评论 -
一个django项目
一、基本使用pip install django 安装django1、不使用pycharm创建一个项目shell >> django-admin startproject classroom #创建项目2、新建一个文件夹存放所有的appshell >> cd classroomshell >> mkdir appshell >&a原创 2019-03-13 14:31:01 · 129 阅读 · 0 评论 -
windows 8.1安装python
一、安装python环境1、下载https://www.python.org/downloads/release/python-352/注意版本和系统的位数,带x64的代表64位,不带的代表32位2、安装:忘了截图了,这个是网上找的3、安装完了,使用时报了一个错误缺失 api-ms-win-crt-runtimel1-1-0.dll 这个问题真是坑死人,我是小白,搞了一天大...原创 2019-03-13 13:37:46 · 1955 阅读 · 0 评论 -
装饰器
据说装饰器采用的是一种切面的思想。即在不改动源码的情况下从切面为函数增加功能。def myl(): print('this is myl')这是一个函数,如果我想实现在运行函数之前打印start 之后打印end 要怎么办呢def myl(): print('start') print('this is myl') print('end')---------------def...原创 2019-03-06 17:39:40 · 83 阅读 · 0 评论 -
上下文管理contextlib
https://www.cnblogs.com/pyspark/articles/8819803.htmlhttps://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001478651770626de401ff1c0d94f379774cabd842222ff000总是在不同函数前后执行...转载 2019-02-25 13:13:45 · 109 阅读 · 0 评论 -
logging
python 标准包,https://www.red-dove.com/python_logging.htmlhttps://www.cnblogs.com/Nicholas0707/p/9021672.htmlimport logging示例:#pythonimport logginglogging.info('this is info') logging.war...转载 2019-02-23 15:05:37 · 369 阅读 · 0 评论 -
python中的重试
安装: pip install retryinghttps://blog.csdn.net/liereli/article/details/79993114@retry 装饰器会对函数不断的重试#默认无限重试@retry()def pick_one(): print('pick') t = random.randint(0, 2) print(t) if ...转载 2019-02-11 15:41:09 · 757 阅读 · 0 评论 -
yaml
参考博客1参考博客2参考博客3字典:用:表示字典的一一对应 用退格表示层级关系(不能用tab,只能用空格,对齐表示相同层级): 后必须有空格才代表字典{c:{a:1,b:2}}c: a: 1 b: 2...原创 2019-02-11 17:24:44 · 168 阅读 · 0 评论 -
python小记
python 中文官方文档:https://yiyibooks.cn/xx/python_352/index.html类和元类类由元类创建type 是一个元类 type('class_name',(par_vlass_name),{})字典不可以是函数博客地址:http://blog.jobbole.com/21351/创建一个类的过程:当做了class Foo(Bar): ...原创 2019-01-30 15:44:43 · 123 阅读 · 0 评论 -
一些函数
datetime()import pytzfrom datetime import datetime, timedeltautc = pytz.utca = datetime.utcnow() # 获取世界时间b = datetime.utcnow().replace(tzinfo=utc)c = datetime.now() #获取当地当时时间d...转载 2019-01-30 15:32:14 · 114 阅读 · 0 评论