Flask

Rollback Many Transactions between tests in Flask

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-06 15:52:53
问题 My tests take a long time to run and I am trying to rollback transactions between tests instead of dropping and creating the tables between tests. The issues is that in some tests I do multiple commits. EDIT: How do I rollback transactions between tests so that tests will run faster Here is the Base class used for testing. import unittest from app import create_app from app.core import db from test_client import TestClient, TestResponse class TestBase(unittest.TestCase): def setUp(self): self

Access Flask session with ReactJS

a 夏天 提交于 2021-02-06 15:51:31
问题 I have a Python Flask server serving not only an webapp but also a set of routes, sort of like an API. In this webapp, I'm using only ReactJS, as in the HTML code is simply a div and ReactJS puts everything in place from there. Only problem is: Flask is taking care of the login process, which means only Flask has access to the credentials of the user and the result of the login. For the ReactJS interface to work properly, it needs an ID (most likely a huge string) of the user and other

What is going on when I set app.wsgi_app = ProxyFix(app.wsgi_app) when running a Flask app on gunicorn?

三世轮回 提交于 2021-02-06 09:45:27
问题 I built a basic web app using Flask, and was able to run it from a virtual machine using its native http server. I quickly realized that with this set up, requests are blocking (I couldn't make concurrent requests for resources; any new request would wait until earlier requests had finished), and decided to try gunicorn to run the app to solve this problem. I followed the documentation, specifically running with this line: gunicorn -w 4 -b 127.0.0.1:4000 myproject:app However, it failed to

Pandas as fast data storage for Flask application

女生的网名这么多〃 提交于 2021-02-06 09:06:35
问题 I'm impressed by the speed of running transformations, loading data and ease of use of Pandas and want to leverage all these nice properties (amongst others) to model some large-ish data sets (~100-200k rows, <20 columns). The aim is to work with the data on some computing nodes, but also to provide a view of the data sets in a browser via Flask . I'm currently using a Postgres database to store the data, but the import (coming from csv files) of the data is slow, tedious and error prone and

What is the difference between Session and db.session in SQLAlchemy?

限于喜欢 提交于 2021-02-06 08:50:49
问题 In the event mapper level docs it says that Session.add() is not supported, but when I tried to do db.session.add(some_object) inside after_insert event it worked, example: def after_insert_listener(mapper, connection, user): global_group = Group.query.filter_by(groupname='global').first() a = Association(user,global_group) db.session.add(a) event.listen(User, 'after_insert', after_insert_listener) Basically any new user should be part of global_group, so I added it in the after_insert event.

What is the difference between Session and db.session in SQLAlchemy?

我的未来我决定 提交于 2021-02-06 08:50:28
问题 In the event mapper level docs it says that Session.add() is not supported, but when I tried to do db.session.add(some_object) inside after_insert event it worked, example: def after_insert_listener(mapper, connection, user): global_group = Group.query.filter_by(groupname='global').first() a = Association(user,global_group) db.session.add(a) event.listen(User, 'after_insert', after_insert_listener) Basically any new user should be part of global_group, so I added it in the after_insert event.

debug Flask server inside Jupyter Notebook

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-06 03:39:52
问题 I want to debug small flask server inside jupyter notebook for demo. I created virtualenv on latest Ubuntu and Python2 (on Mac with Python3 this error occurs as well), pip install flask jupyter. However, when I create a cell with helloworld script it does not run inside notebook. from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run(debug=True,port=1234) File "/home/***/test/local/lib/python2.7/site-packages

CV学习笔记(二十七):Python Base64 格式图片上传

浪子不回头ぞ 提交于 2021-02-06 00:45:53
作者:云时之间 来源:知乎 链接: https://zhuanlan.zhihu.com/p/158118019 编辑:王萌 一:为什么要使用base64格式传输文件? 通常我们在使用服务的时候,数据从我们的设备传输到服务器,往往会有两种方式:一是直接传输文件,但这种情况受网络情况影响较大,文件可能传不过去,并且文件直接在网路上传播,你的数据安全就保证不了。因此需要一种加密格式,也就是我们使用的第二种方法,base64格式加密。有对base64算法加密的过程感兴趣的推荐看一下这一篇博客: https://blog.csdn.net/robertcpp/article/details/51628647 对base64的编码转码都有比较详细的介绍。 简单来说就是把一张图片数据加密成一串字符,使用该字符串代替图像地址。 个人觉得,使用base64可以带来以下优点 1.减少了HTTP请求 2.某些文件可以避免跨域的问题 3.避免了图片更新时要重新上传,还要清理缓存的问题 但是也带来了一些问题: 图片完成后还需要base64编码,因此,增加了一定的工作量,虽然不多。并且使用 base64 编码的前提是图片足够小,拿一张3KB的图片为例,一张 3.27 KB logo 图片,已经很小了,但是如果将其制作转化成 base64 编码,生成的 base64 字符串编码足足有 4406 个,也就是说

Pass Variable from python (flask) to HTML in render template?

落花浮王杯 提交于 2021-02-05 20:54:24
问题 The web server works (python flask) but when I go to the website, where the value of animal should be (dog) it shows the variable name animal. (There is more to the code but this is the most simplistic version which is the same concept. Let's say I have these lines of code in my python script running python flask. animal = dog return render_template('index.html', value=animal) and in my HTML <h3>I like the animal: {{ value }}<h3> but rather than displaying 'dog' it displays the variable name

Display multiple mpld3 exports on a single HTML page

半城伤御伤魂 提交于 2021-02-05 20:30:40
问题 I've found the mpld3 package to be brilliant for exporting a matplolib plot to HTML and displaying this via a flask app. Each export comes with a lot of JS which seems unnecessary duplication if you want to display multiple plots within a single page. However I'm not well enough versed in JS to extract the relevant components and then loop through them. The .fig_to_dict method gives the necessary JSON to display each chart but then I'm left wondering what JS/ template work is needed to