天道酬勤,学无止境

flask

Flask Admin ModelView different fields between CREATE and EDIT

In a Flask app using Flask Admin I would like to be able to define different form fields in the Edit section of a ModelView than those in the Create section. The form_columns setting applies to both Create and Edit, but I can't seem to find a way to give different sets of columns to each section.

2021-06-15 17:34:46    分类:问答    python   flask   flask-admin

How to return image stream and text as JSON response from Python Flask API

From a Python Flask API, I want to return an image stream and also some text in a single API response. Something like this: { 'Status' : 'Success', 'message': message, 'ImageBytes': imageBytes } Also, I would like to know what would be the best format to use for imageBytes, so that the client applications (Java / JQuery) can parse and reconstruct the image. If the above approach is not correct, please suggest a better approach.

2021-06-15 15:51:13    分类:问答    python   flask

Flask decorator : Can't pass a parameter from URL

i'm quite new with flask and i'm trying to use the migthy power of decorators :p I read lot of things and found tons of topics about python decorators here but nothing really helpful. @app.route('groups/<id_group>') @group_required(id_group) @login_required def groups_groupIndex(id_group): #do some stuff return render_template('index_group.html') This is the error i get : @group_required(id_group), NameError: name 'id_group' is not defined Ok, id_group is not defined yet, but I don't understand why i CAN use the id_group parameter from the URL in the function groups_groupIndex but NOT in the

2021-06-15 14:04:27    分类:问答    python   flask   decorator   python-decorators

Container localhost does not exist error when using Keras + Flask Blueprints

I am trying to serve a machine learning model via an API using Flask's Blueprints, here is my flask __init__.py file from flask import Flask def create_app(test_config=None): app = Flask(__name__) @app.route("/healthcheck") def healthcheck() -> str: return "OK" # Registers the machine learning blueprint from . import ml app.register_blueprint(ml.bp) return app The ml.pyfile which contains the blueprint for the /ml endpoint import numpy as np from . import configuration as cfg import tensorflow as tf from flask import ( Blueprint, flash, request, url_for ) bp = Blueprint("ml", __name__, url

2021-06-15 12:53:58    分类:问答    python   flask   keras

Flask-admin - how to change formatting of columns - get URLs to display

Question on flask-admin. I setup flask-admin and one of the models i created is pulling urls and url titles from a mysql database. Using flask-admin, how to i get flask-admin to render the urls instead of just text? So make it easier for users to just click on the link from the flask-admin app. Thank you. I found something on the flask-admin site called column formatters, but not sure how to implement. Does anyone have an example they can share? Thanks.

2021-06-15 12:12:51    分类:问答    python   flask   flask-admin

how to correctly pass a json object to flask server using jquery ajax

i want to pass a json object which contains nested objects from my client to my server. on the client side, my data structure looks like this: var response = {}; response['screening'] = '1'; response['assistance'] = 'wheelchair access'; response['guests'] = {}; response['guests']['1'] = {} response['guests']['1']['first'] = 'John' response['guests']['1']['last'] = 'Smith' response['guests']['2'] = {} response['guests']['2']['first'] = 'Dave' response['guests']['2']['last'] = 'Smith' and my ajax call looks like this: $.ajax({ type: "POST", url: window.location.pathname, data: response }).done

2021-06-15 11:57:49    分类:问答    javascript   python   ajax   json   flask

Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)

I am always getting this error when running my Flask App with Websockets. I have tried to follow this guide - http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent I have a flask app that provides the GUI interface for my network sniffer. The sniffer is inside a thread as shown below : ( l is the thread for my sniffer; isRunning is a boolean to check if the thread is already running) try: if l.isRunning == False: # if the thread has been shut down l.isRunning = True # change it to true, so it could loop again running = True l.start() # starts the forever loop / declared

2021-06-15 11:53:13    分类:问答    python   multithreading   flask   socket.io   flask-socketio

Send html email using flask in Python

I want to send HTML webpage as a mail body using Python and Flask. I tried using MIME module, but somehow I am not being able to send mail. If anyone has any expertise on this, can you please help me. It would be great if you could provide some code as well.

2021-06-15 11:01:50    分类:问答    python   html   email   flask   webpage

Flask app hangs while processing the request

I have a simple flask app, single page, upload html and then do some processing on it on the POST; at POST request; i am using beautifulsoup, pandas and usually it takes 5-10 sec to complete the task. at the end i export the resultant dataframe to excel with pandas(with the update of the previous stored excel if present). and on GET request i return the result of this dataframe. Now issue is... app gives no response while those 5-10 sec.; even if i visit my app from another computer; it will show after the completion of those 5-10 sec. It means if any user of this app has uploaded his file

2021-06-15 10:57:49    分类:问答    python   flask   tornado

Catching Flask abort status code in tests?

I have an abort() in my flask class based view. I can assert that an abort has been called, but I cannot access the 406 code in my context manager. views.py from flask.views import View from flask import abort class MyView(View): def validate_request(self): if self.accept_header not in self.allowed_types: abort(406) tests.py from werkzeug.exceptions import HTTPException def test_validate_request(self): # Ensure that an invalid accept header type will return a 406 self.view.accept_header = 'foo/bar' with self.assertRaises(HTTPException) as http_error: self.view.validate_request() self

2021-06-15 10:36:04    分类:问答    python   flask