Which SQLAlchemy column type should be used for binary data?

When storing binary data, use the LargeBinary type. Despite its name, it is appropriate for any sized binary data. data = db.Column(db.LargeBinary) Read the data from the uploaded file in your Flask view. audio.data = request.files[‘data’].read() Rather than storing the data in the database, it’s typically better to store files in the filesystem, and store … Read more

Sending array data with jquery and flask

When sending POST data containing values that are arrays or objects, jQuery follows a PHP convention of adding brackets to the field names. It’s not a web standard, but because PHP supports it out of the box it is popular. As a result, the correct way of handling POST data with lists on the Flask … Read more

How can we call one route from another route with parameters in Flask?

You have two options. Option 1: Make a redirect with the parameters that you got from the route that was called. If you have this route: import os from flask import Flask, redirect, url_for @app.route(‘/abc/<x>/<y>’) def abc(x, y): callanothermethod(x,y) You can redirect to the route above like this: @app.route(‘/xyz’, methods = [‘POST’, ‘GET’]) def xyz(): … Read more

How to GET data in Flask from AJAX post

You can compose your payload in your ajax request as so: $(document).ready(function(){ var clicked; $(“.favorite”).click(function(){ clicked = $(this).attr(“name”); $.ajax({ type : ‘POST’, url : “{{url_for(‘test’)}}”, contentType: ‘application/json;charset=UTF-8’, data : {‘data’:clicked} }); }); }); In your flask endpoint, you can extract the value as follows: @app.route(‘/test/’, methods=[‘GET’,’POST’]) def test(): clicked=None if request.method == “POST”: clicked=request.json[‘data’] return … Read more

How to use Flask-Script and Gunicorn

As Dhaivat said, you can just use your Flask app directly with Gunicorn. If you still want to use Flask-Script, you will need to create a custom Command. I don’t have any experience with Gunicorn, but I found a similar solution for Flask-Actions and ported it to Flask-Script, although be warned, it’s untested. from flask_script … Read more