Questions tagged [flask]
Flask is a lightweight framework for developing web applications using Python.
flask
55,825
questions
1279
votes
26
answers
1.9m
views
Get the data received in a Flask request
I want to be able to get the data sent to my Flask app. I've tried accessing request.data but it is an empty string. How do you access request data?
from flask import request
@app.route('/', methods=...
822
votes
24
answers
1.1m
views
How to serve static files in Flask
So this is embarrassing. I've got an application that I threw together in Flask and for now it is just serving up a single static HTML page with some links to CSS and JS. And I can't find where in the ...
716
votes
18
answers
842k
views
Configure Flask dev server to be visible across the network
I'm not sure if this is Flask specific, but when I run an app in dev mode (http://localhost:5000), I cannot access it from other machines on the network (with http://[dev-host-ip]:5000). With Rails in ...
683
votes
15
answers
914k
views
Return JSON response from Flask view
I have a function that analyzes a CSV file with Pandas and produces a dict with summary information. I want to return the results as a response from a Flask view. How do I return a JSON response?
@...
652
votes
13
answers
592k
views
How do you access the query string in Flask routes?
How do you access query parameters or the query string in Flask routes? It's not obvious from the Flask documentation.
The example route /data below illustrates the context that I would like to access ...
624
votes
8
answers
827k
views
How can I get the named parameters from a URL using Flask?
When the user accesses this URL running on my flask app, I want the web service to be able to handle the parameters specified after the question mark:
http://10.1.1.1:5000/login?username=alex&...
510
votes
13
answers
883k
views
How to get POSTed JSON in Flask?
I'm trying to build a simple API using Flask, in which I now want to read some POSTed JSON. I do the POST with the Postman Chrome extension, and the JSON I POST is simply {"text":"lalala"}. I try to ...
444
votes
10
answers
761k
views
How to use cURL to send Cookies?
I read that sending cookies with cURL works, but not for me.
I have a REST endpoint like this:
class LoginResource(restful.Resource):
def get(self):
print(session)
if 'USER_TOKEN' ...
418
votes
15
answers
386k
views
Auto reloading python Flask app upon code changes
I'm investigating how to develop a decent web app with Python. Since I don't want some high-order structures to get in my way, my choice fell on the lightweight Flask framework. Time will tell if this ...
364
votes
11
answers
729k
views
Redirecting to URL in Flask
I'm trying to do the equivalent of Response.redirect as in C# - i.e.: redirect to a specific URL - how do I go about this?
Here is my code:
import os
from flask import Flask
app = Flask(__name__)
@...
358
votes
11
answers
243k
views
Can Flask have optional URL parameters?
Is it possible to directly declare a flask URL optional parameter?
Currently I'm proceeding the following way:
@user.route('/<userId>')
@user.route('/<userId>/<username>')
def show(...
350
votes
16
answers
744k
views
How do I get Flask to run on port 80?
I have a Flask server running through port 5000, and it's fine. I can access it at http://example.com:5000
But is it possible to simply access it at http://example.com? I'm assuming that means I have ...
341
votes
10
answers
447k
views
How to execute raw SQL in Flask-SQLAlchemy app
How do you execute raw SQL in SQLAlchemy?
I have a python web app that runs on flask and interfaces to the database through SQLAlchemy.
I need a way to run the raw SQL. The query involves multiple ...
341
votes
5
answers
422k
views
json.dumps vs flask.jsonify
I am not sure I understand the purpose of the flask.jsonify method. I try to make a JSON string from this:
data = {"id": str(album.id), "title": album.title}
but what I get with json.dumps differs ...
334
votes
4
answers
333k
views
How to get http headers in flask?
Using Flask, how can I read HTTP headers? I want to check the authorization header which is sent by the client.