标签:路径 pass 取出 flask mail 磁盘io cti 体验 属性
一、缓存
1 from flask import Flask 2 from flask_caching import Cache 3 4 app = Flask(__name__) 5 6 cache_info = { 7 "CACHE_TYPE": "redis", 8 "CACHE_REDIS_URL": "redis://:123456@localhost:6379/2" 9 } 10 11 cache = Cache() 12 cache.init_app(app, config=cache_info) 13 14 @app.route(‘/‘) 15 @cache.cached(timeout=60) 16 def hello_world(): 17 return ‘Hello World!‘ 18 19 if __name__ == ‘__main__‘: 20 app.run(host=‘0.0.0.0‘, debug=True)
二、文件上传
首先在html页面的form标签加上属性 enctype="multipart/form-data",这个一定一定记得加上。
1 <form action="" method="post" enctype="multipart/form-data">
取出文件操作:
1 file = request.files.get("file_name")
存储到磁盘上:
1 file_path = "存储文件的路径" 2 file.save(file_path)
三、发送邮件
直接上代码,一看就能懂:
1 from flask import Flask 2 from flask_mail import Mail, Message 3 4 app = Flask(__name__) 5 6 app.config["MAIL_SERVER"] = "smtp.163.com" # 邮箱服务器地址,在设置里查看,这是个示例 7 app.config["MAIL_USERNAME"] = "******@163.com" 8 app.config["MAIL_PASSWORD"] = "*********" 9 10 mail = Mail() 11 mail.init_app(app) 12 13 @app.route(‘/‘) 14 def hello(): 15 content = "<h1>小伙子你开什么车?</h1>" 16 msg = Message("Hello", sender="******@163.com", recipients=["******@163.com", ], html=content) 17 mail.send(msg) 18 return "Hello World" 19 20 if __name__ == ‘__main__‘: 21 app.run(host=‘0.0.0.0‘, debug=True)
标签:路径 pass 取出 flask mail 磁盘io cti 体验 属性
原文地址:https://www.cnblogs.com/wuzc/p/12052093.html