Flask

Setting my <img> source to a file path outside of flask static folder

人盡茶涼 提交于 2021-01-28 11:40:59
问题 I need to display some images and these image filepaths are outside of flask's static folder stored on on network folders. <img src="{{ filepath }}"> # /some/external/network/folder/img.jpg However this is not working and I get a broken image icon, however I can paste the image path into my browser and confirm its accessible. I need this application to be able to accept image sources from anywhere, so I can't update my static folder to the network folder. I also can't load the images to the

How to use cx_Oracle session pool with Flask gracefuly?

我是研究僧i 提交于 2021-01-28 11:33:09
问题 I'm a newbie to Python and Flask, and I use Oracle, when learning Flask tutorial, I code as follow, but it smells really bad, please help me with these questions, thanks a lot! 1) need I release connection to poll explicitly? 2) how can I implement poll acquire and release gracefully? def get_dbpool(): if not hasattr(g, 'db_pool'): g.dbPool = connect_db() return g.dbPool @app.teardown_appcontext def close_db(error): if hasattr(g, 'db_pool'): g.dbPool.close() @app.route('/') def hello_world():

Flask-Mail and Redis Queue library integration giving error

此生再无相见时 提交于 2021-01-28 11:19:39
问题 I am using Flask-Mail extension to enable mail sending in the app. I was not able to get celery working with flask so I looked up some other library and found Redis Queue. Code: from flask.ext.mail import Mail,Message from rq import Queue mail = Mail() # mail.init_app(app) is done in top app.py q = Queue() @mod.route('/test') def m11(): msg = Message("Signup Successfull", recipients=['abc@gmail.com']) msg.body = "Hello there, Welcome!" q.enqueue(mail.send, msg) return 'done' When I run the

Reading a CSV file in Flask and iterating through Jinga2

北城余情 提交于 2021-01-28 10:25:15
问题 I am trying to display data on my web app from a CSV file using Flask. The below code reads my CSV file and assigns stocklist as the variable for my data. In the HTML code below it, using jinga logic, I iterate through stocklist however my CSV columns are returned as rows (see sample output and pic). How do I display the rows correctly? My python function: @app.route('/stocks') def Stocks(): filename = 'stock_scraper - dev.csv' data = pandas.read_csv(filename, header=0) stocklist = list(data

Reading a CSV file in Flask and iterating through Jinga2

岁酱吖の 提交于 2021-01-28 10:12:22
问题 I am trying to display data on my web app from a CSV file using Flask. The below code reads my CSV file and assigns stocklist as the variable for my data. In the HTML code below it, using jinga logic, I iterate through stocklist however my CSV columns are returned as rows (see sample output and pic). How do I display the rows correctly? My python function: @app.route('/stocks') def Stocks(): filename = 'stock_scraper - dev.csv' data = pandas.read_csv(filename, header=0) stocklist = list(data

Python to Javascript JSON objects (Flask) [duplicate]

南楼画角 提交于 2021-01-28 08:11:48
问题 This question already has answers here : JavaScript raises SyntaxError with data rendered in Jinja template (3 answers) Closed 2 years ago . I am trying to create a simple Flask app where an array of integers is generated on the server and sent to the client. I want to view the array of integers in the console. Here is some sample (working) code in app.py: from flask import Flask, render_template, request, url_for import random, json app = Flask(__name__) @app.route('/', methods=['GET']) def

Unresponsive requests- understanding the bottleneck (Flask + Oracle + Gunicorn)

[亡魂溺海] 提交于 2021-01-28 08:03:50
问题 I'm new to Flask/Gunicorn and have a very basic understanding of SQL. I have a Flask app that connects to a remote oracle database with cx_oracle. Depending on the app route selected, it runs one of two queries. I run the app using gunicorn -w 4 flask:app . The first query is a simple query on a table with ~70000 rows and is very responsive. The second one is more complex, and queries several tables, one of which contains ~150 million rows. Through sprinkling print statements around, I notice

Initialising a Flask app running with Apache and mod_wsgi

拟墨画扇 提交于 2021-01-28 07:34:02
问题 I've got a Flask app running under Apache using mod_wsgi. The app needs to do do some initialisation, including setting some top-level variables that need to be accessible inside the request handlers, before it receives any requests. At the moment this initialisation code is just top-level statements in app.py before the request handling methods: from flask import Flask, Response, request <other app imports> APP = Flask(__name__) # initialisation code @APP.route(<URL for request #1>) def

Getting Datatables and Sparklines to play nice together?

混江龙づ霸主 提交于 2021-01-28 07:28:46
问题 Im currently trying to get Datatables and the Sparklines packages to work together kind of like below: (This stuff is all written in R however) I realize my issue is similar to this one... However, even after looking at some of the code and adapting it to my own, I was only able to render one or the other.. either the data from my server on the chart or the sparklines rendered with all data missing - never both together... Here's the code <table id="table_id" class="display"> <thead> <tr> <th

Initialising a Flask app running with Apache and mod_wsgi

喜你入骨 提交于 2021-01-28 07:20:22
问题 I've got a Flask app running under Apache using mod_wsgi. The app needs to do do some initialisation, including setting some top-level variables that need to be accessible inside the request handlers, before it receives any requests. At the moment this initialisation code is just top-level statements in app.py before the request handling methods: from flask import Flask, Response, request <other app imports> APP = Flask(__name__) # initialisation code @APP.route(<URL for request #1>) def