随笔分类 -  Flask

摘要:1. 目录结构 一般情况下,Django很系统、统一。Flask项目目录风格不同一,即使用上了蓝图。 2. 数据库迁移 Flask要用第三方extensions,而Django自带,这个很方便。 3. 模块化 Flask是用蓝图。Django可以自动生成 ,并在Django的项目的settings那 阅读全文
posted @ 2018-08-23 11:48 Rocin 阅读(4205) 评论(0) 推荐(0)
摘要:TL;DR,可以直接看下面的总结 问题1:为什么app.config['DEBUG'] = True,然后flask run并没有开启debugger和reloading,而直接运行脚本(python manage.py)却可以生效? 然后 可以看到, 在代码配置app.debug=True,然后在 阅读全文
posted @ 2018-07-05 20:29 Rocin 阅读(5312) 评论(0) 推荐(0)
摘要:传送门 来自作者的PPT https://speakerdeck.com/mitsuhiko/advanced flask patterns?slide=46 阅读全文
posted @ 2018-06-30 11:44 Rocin 阅读(361) 评论(0) 推荐(0)
摘要:传送门 1. http://flask.pocoo.org/docs/1.0/appcontext/ storing data 2. http://flask.pocoo.org/docs/1.0/appcontext 3. http://flask.pocoo.org/docs/1.0/appco 阅读全文
posted @ 2018-06-27 10:57 Rocin 阅读(785) 评论(0) 推荐(0)
摘要:1. 疑问 flask web狗书的 git reset hard 16b flask profile profile dir="./profile",生成了后缀为 .prof的文件,我怎么查看这些文件呢? 我发起了一个issue:https://github.com/miguelgrinberg/ 阅读全文
posted @ 2018-06-07 14:52 Rocin 阅读(1663) 评论(0) 推荐(0)
摘要:flasky中git reset hard 8e 问题 1. 使用flask mail通过163邮箱的smtp服务发送token认证邮件,要关闭TLS才能发送 原理 1. 还在研究中 结果 阅读全文
posted @ 2018-05-24 16:25 Rocin 阅读(123) 评论(0) 推荐(0)
摘要:1. Flask SQLAlchemy 1.1 参考: http://flask sqlalchemy.pocoo.org/2.3/ https://github.com/janetat/flasky/commits/master?after=f0d6546112480b0f728194982e3f 阅读全文
posted @ 2018-05-21 13:54 Rocin 阅读(157) 评论(0) 推荐(0)
摘要:1 概念 Flask框架中的信号基于blinker,其主要就是让开发者可是在flask请求过程中定制一些用户行为。 2. 信号和Flask请求拓展的区别,例如\@before_request Flask钩子(通常出现在蓝图或应用程序现存的方法中,比如一些内置装饰器,例如before_request) 阅读全文
posted @ 2018-05-17 15:14 Rocin 阅读(203) 评论(0) 推荐(0)
摘要:1. 多APP应用 请求进来时,可以根据URL的不同,交给不同的APP处理。一般用蓝图也可以实现。一般不写多app应用。 看DispatcherMiddleware的源码,看app2.__call__源码 原理其实就是URL分割,然后请求分发给指定的app。然后请求分配给制定的app,之后app也按 阅读全文
posted @ 2018-05-16 21:24 Rocin 阅读(1896) 评论(1) 推荐(0)
摘要:参考 1. http://flask.pocoo.org/docs/1.0/advanced_foreword/ thread locals in flask 2. https://zhuanlan.zhihu.com/p/33732859 3. https://www.zhihu.com/ques 阅读全文
posted @ 2018-05-10 14:11 Rocin 阅读(287) 评论(0) 推荐(0)
摘要:概念 1. 如果项目很大,不写在单独一个py文件里,此时需要蓝图;蓝图提供了一种组织python packages的方式 2. 蓝图为应用提供模块化,划分目录。 3. 一个蓝图代表一个包(package,__init__,可以查看flasky的例子),有自己的templates, static等等。 阅读全文
posted @ 2018-05-10 09:23 Rocin 阅读(174) 评论(0) 推荐(0)
摘要:其实就是封装旧酒,装进新瓶,自己再加点料。留坑,还没有用到。 Flask的请求扩展就是Django的中间件。Django的中间件不是Flask的中间件 问题:这是不是Flask extensions的实现原理?看见都是这样用第三方扩展的。日后研究 阅读全文
posted @ 2018-05-10 08:00 Rocin 阅读(2719) 评论(0) 推荐(1)
摘要:例子1. 处理请求之前 @app.before_request 在请求之前,这个被装饰的函数会被执行 用户登录验证代码可以在这里写 例子2. @app.before_request, @app.after_request最常用 因为错误页面请求到了,所以状态码为200 例子3. @app.befor 阅读全文
posted @ 2018-05-09 23:25 Rocin 阅读(367) 评论(0) 推荐(0)
摘要:1. 像snap一样阅后即焚,在服务器端临时存储数据的地方,如显示错误信息。(也可以用session实现) 2. Flash的底层是session做的,所以要secret_key。可以看源码 3. flash()存储数据,get_flashed_messages()获得数据 例子1. flash向某 阅读全文
posted @ 2018-05-09 21:34 Rocin 阅读(343) 评论(0) 推荐(0)
摘要:1. Flask、Django、Tornado框架区别 2. Flask快速入门 3. 配置文件 4. 路由系统 5. 模板 6. 请求&响应相关 7. session & cookie 8. 闪现(from flask import flask, get_flashed_message) 9. 蓝 阅读全文
posted @ 2018-05-09 18:42 Rocin 阅读(143) 评论(0) 推荐(0)
摘要:参考: https://blog.csdn.net/nunchakushuang/article/details/74652877 http://portal.xiaoxiangzi.com/Programme/Python/7890.html https://www.zhihu.com/quest 阅读全文
posted @ 2018-05-09 18:38 Rocin 阅读(472) 评论(0) 推荐(0)
摘要:请求都封装在request对象里面了 阅读全文
posted @ 2018-05-08 22:12 Rocin 阅读(117) 评论(0) 推荐(0)
摘要:一. flask在哪里找模板? 1. from flask import Flask 2. 从Flask中查看源码,会跳转到app.py,app.py里有class Flask,class Flask里面有__init__ 3. 从源码可见,默认模板路径是当前路径的templates目录 4. fr 阅读全文
posted @ 2018-05-08 15:09 Rocin 阅读(225) 评论(0) 推荐(0)
摘要:一. 配置文件 flask中的配置文件是一个flask.config.Config对象(继承字典),默认配置为 方法1,不常用 方法2 方法3,常用,app.config.from_object("python类或类的路径") settings.py hello.py https://github. 阅读全文
posted @ 2018-05-08 15:09 Rocin 阅读(145) 评论(0) 推荐(0)
摘要:一. 路由和响应函数(View function)的映射是通过装饰器实现的 1. 2. app.route源码 def route(self, rule, options): """A decorator that is used to register a view function for a 阅读全文
posted @ 2018-05-08 15:08 Rocin 阅读(206) 评论(0) 推荐(0)