12 2021 档案
摘要:from matplotlib import pyplot as plt import matplotlib y_3 = [11,17,16,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22] y_10 =[26,28,1
阅读全文
摘要:1. 无参装饰器(无函数返回值) import time def timer(func): ''' prints function time ''' def wrapper(): start = time.time() func() print('function %s run time %s' %
阅读全文
摘要:from matplotlib import pyplot as plt import matplotlib #设置中文可以显示的字体 font = {"family":"MicroSoft YaHei","weight":"bold"} # matplotlib.rc("font",**font)
阅读全文
摘要:<原文网址:https://dormousehole.readthedocs.io/en/latest/quickstart.html#cookies> 1. Cookies: 要访问 cookies ,可以使用 cookies 属性。可以使用响应 对象 的 set_cookie 方法来设置 coo
阅读全文
摘要:1. 最基本的蓝图示例。 from flask import Blueprint, render_template, abort from jinja2 import TemplateNotFound simple_page = Blueprint('simple_page', __name__,
阅读全文
摘要:1. flask中的类视图如何使用 from flask import Flask, views, url_for app = Flask(__name__) def auth(func): def inner(*args, **kwargs): result = func(*args, **kwa
阅读全文
摘要:1.可传入参数: @app.route('/user/<username>') #常用的 不加参数的时候默认是字符串形式的 @app.route('/post/<int:post_id>') #常用的 #指定int,说明是整型的 @app.route('/post/<float:post_id>')
阅读全文
摘要:配置管理 复杂的项目需要配置各种环境。如果设置项很少,可以直接硬编码进来,比如下面的方式: app = Flask(__name__) app.config['DEBUG'] = True app.config是flask.config.Config类的实例,继承自Python内置数据结构dict,
阅读全文
摘要:from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
阅读全文
摘要:1.获取请求数据及响应 - request - request.form #接收POST或者PUT请求的数据 - request.args #GET请求的数据,不是完全意义上的字典,通过.to_dict可以转换成字典 - request.querystring #GET请求,bytes形式的 - r
阅读全文
摘要:目录 APScheduler简介 支持的后端存储作业 集成的Python框架 APScheduler下载安装 APScheduler组件 各组件简介 调度器 作业存储器 执行器 触发器 使用 添加作业 只执行一次 间隔执行 APScheduler简介 APScheduler(Advanced Pyt
阅读全文
摘要:#logger文档地址:https://docs.python.org/zh-cn/3/library/logging.html 目录 什么是日志 什么时候使用日志 basicConfig handler Traceback 文件配置 日志切割 根据日期时间分割日志 根据文件大小分割日志 推荐配置
阅读全文
摘要:项目开发初期,为了测试方便,我们总要造不少假数据到系统中,尽量模拟真实环境。比如要创建一批用户名,创建一段文本,电话号码,街道地址、IP地址等等。平时我们基本是键盘一顿乱敲,随便造个什么字符串出来,当然谁也不认识谁。现在你不要这样做了,用Faker就能满足你的一切需求。 1. 安装 pip inst
阅读全文
摘要:目录 About urllib、urllib2、urllib3傻傻分不清楚 urllib.request 请求 响应 request对象 Cookie 代理 下载 urllib.error urllib.parse urllib.robotparser Robots协议 RobotFileParse
阅读全文
摘要:flask的中间件功能和Django类似,不同的是使用的是使用3个装饰器来实现的; 1.@app.before_first_request :请求第1次到来执行1次,之后都不执行; 2.@app.before_request:请求到达视图之前执行;(改函数不能有返回值,否则直接在当前返回) 3.@a
阅读全文
摘要:str.capitalize 将字符串的一个字符转换为大写 ** str.center 返回指定宽度的居中的字符串 *** str.count 返回指定字符在字符串内出现的次数 **** str.endswith 检查字符串是否以指定字符结尾 *** str.startswith 检查字符串是否在指
阅读全文