Skip to main content

Questions tagged [flask]

Flask is a lightweight framework for developing web applications using Python.

flask
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=...
ddinchev's user avatar
  • 34.5k
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 ...
hughdbrown's user avatar
  • 48.6k
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 ...
sa125's user avatar
  • 28.7k
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? @...
Code Ninja's user avatar
  • 7,093
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 ...
Tampa's user avatar
  • 77.4k
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&...
Alex Stone's user avatar
  • 47.1k
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 ...
kramer65's user avatar
  • 52.8k
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' ...
daydreamer's user avatar
  • 90.5k
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 ...
Passiday's user avatar
  • 7,905
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__) @...
iJade's user avatar
  • 23.6k
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(...
Noor's user avatar
  • 20k
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 ...
quantumtremor's user avatar
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 ...
starwing123's user avatar
  • 3,523
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 ...
Sergei Basharov's user avatar
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.
emil's user avatar
  • 6,314

15 30 50 per page
1
2 3 4 5
3722