Flask

Jinja2 check if value exists in list of dictionaries

你离开我真会死。 提交于 2021-02-09 00:24:58
问题 I am trying to check if a value exists inside a list with dictionaries. I use flask 1.0.2. See example below: person_list_dict = [ { "name": "John Doe", "email": "johndoe@mydomain.com", "rol": "admin" }, { "name": "John Smith", "email": "johnsmith@mydomain.com", "rol": "user" } ] I found two ways to solve this problem, can you tell me which is better?: First option: jinja2 built-in template filter "map" <pre>{% if "admin" in person_list_dict|map(attribute="rol") %}YES{% else %}NOPE{% endif %}

Can't create test client during unit test of Flask app

耗尽温柔 提交于 2021-02-08 14:10:31
问题 I am trying to find out how to run a test on a function which grabs a variable value from session['user_id'] . This is the specific test method: def test_myProfile_page(self): with app.test_client() as c: with c.session_transaction() as sess: sess['user_id'] = '1' rv = c.get('/myProfile') assert 'My Profile' in rv.data This is the view being tested: @app.route('/myProfile') def myProfile(): if not session.get('logged_in'): return render_template('login.html') else: profileID = session['user

Using celery with Flask app context gives “Popped wrong app context.” AssertionError

空扰寡人 提交于 2021-02-08 13:45:41
问题 I'm more or less using the setup to run Celery tasks using your flask app context from here: http://flask.pocoo.org/docs/0.10/patterns/celery/ I'm getting the same error message as Create, manage and kill background tasks in flask app but, I'm getting it in the actual worker where the Celery task is being executed. Here is the trace: worker_1 | Traceback (most recent call last): worker_1 | File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task worker_1 | R

<sqlite3.Row object at 0x1017fe3f0> instead of database contents

拈花ヽ惹草 提交于 2021-02-08 13:21:14
问题 My templates is this: {% for order in orders %} <li><h2>{{ order}}</h2> {% endfor %} and my routing function is this: @app.route('/order_history') def orderhistory(): db = get_db() cur = db.execute('select * from order_items') orders = cur.fetchall() return render_template('order_history.html', orders = orders) Any idea why I am getting row object locations instead of the db contents? 回答1: You need to get the data from the rows: {% for order in orders %} <li><h2>{{ order[0] }}</h2></li> {%

What service to use for deploying my flask + dash application

爱⌒轻易说出口 提交于 2021-02-08 12:15:29
问题 I am building a small application with dash and flask. Where my user can upload his csv/excel file and have a look at the graphs being generated. I assume the size of each excel file could be around hardly 50MB max / week. I have ' ZERO ' knowledge on servers and deployment etc. Can anyone guide or enlighten me on this area. Also this application is just for an internal purpose so we are not allowed to go easy on the budget. My random google searches gave me options like, 1. AWS 2. Heroku

What service to use for deploying my flask + dash application

无人久伴 提交于 2021-02-08 12:14:27
问题 I am building a small application with dash and flask. Where my user can upload his csv/excel file and have a look at the graphs being generated. I assume the size of each excel file could be around hardly 50MB max / week. I have ' ZERO ' knowledge on servers and deployment etc. Can anyone guide or enlighten me on this area. Also this application is just for an internal purpose so we are not allowed to go easy on the budget. My random google searches gave me options like, 1. AWS 2. Heroku

What is correct way to use Flask-SQLAlchemy in Flask server?

回眸只為那壹抹淺笑 提交于 2021-02-08 11:39:40
问题 This is model code, I have tested this code, it is no error and it can create tables, records in DB createdb.py app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:@localhost:3306/ai' db = SQLAlchemy(app) if __name__ == 'createdb': db.reflect() db.drop_all() db = SQLAlchemy(app) class Class(db.Model): id = db.Column(db.Integer, primary_key=True, unique=True, autoincrement=True) label = db.Column(db.String(255), unique=True, nullable=False) def __init__(self,

reading flask.session with angularjs

强颜欢笑 提交于 2021-02-08 11:29:22
问题 Is there a way to access something in session set with flask.session from angular.js on the client side? I am trying to pass data and store to session in the same call from flask and be able to read it from angular later on in the flow. I am not using the templating system. For the pages, I am only serving up the index file and then using Angular to do the rest. This is my call for the index file: @app.route("/") def index(): return make_response(open('templates/index.html').read()) 回答1: If

reading flask.session with angularjs

点点圈 提交于 2021-02-08 11:29:21
问题 Is there a way to access something in session set with flask.session from angular.js on the client side? I am trying to pass data and store to session in the same call from flask and be able to read it from angular later on in the flow. I am not using the templating system. For the pages, I am only serving up the index file and then using Angular to do the rest. This is my call for the index file: @app.route("/") def index(): return make_response(open('templates/index.html').read()) 回答1: If

How to execute long requests

痴心易碎 提交于 2021-02-08 11:27:55
问题 I am working on building a gui/dashboard type of thing thru which I take input from user.. and when user press submits.. I gather response and fire a job in back end. What I am hoping to achive is.. When the user press submits: and that long job is being processed, I show something like: "Your job has been submitted succesfully) submitted and when it is finished.. I refresh the page to take user to that page. Here is how my route.py snippet looks like @app.route('/',methods=['POST']) def get