Questions tagged [flask]

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

Flask is a web application framework for . It has exceptional documentation, a large number of extensions and a friendly community on Discord. It is open source and BSD-3-Clause licensed.

Resources

Related Tags

45517 questions
927
votes
20 answers

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=['GET', 'POST']) def parse_request(): data =…
ddinchev
  • 29,115
  • 26
  • 82
  • 124
646
votes
20 answers

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 documentation Flask describes returning static…
hughdbrown
  • 42,826
  • 20
  • 80
  • 102
558
votes
14 answers

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? @app.route("/summary") def summary(): d =…
Code Ninja
  • 5,835
  • 4
  • 14
  • 12
540
votes
15 answers

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 dev mode, for example, it works fine. I couldn't…
sa125
  • 25,703
  • 36
  • 105
  • 149
496
votes
10 answers

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 that data. If someone requests something like…
Tampa
  • 62,379
  • 105
  • 250
  • 388
456
votes
8 answers

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&password=pw1 #I just want to be able to manipulate the…
Alex Stone
  • 41,555
  • 51
  • 213
  • 379
398
votes
10 answers

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 read the JSON using the following…
kramer65
  • 39,074
  • 90
  • 255
  • 436
340
votes
6 answers

How to use cURL to send Cookies?

I read that Send cookies with curl works, but not for me. I have a REST endpoint as: class LoginResource(restful.Resource): def get(self): print(session) if 'USER_TOKEN' in session: return 'OK' return 'not…
daydreamer
  • 73,989
  • 165
  • 410
  • 667
313
votes
5 answers

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 from what I get with…
Sergei Basharov
  • 43,294
  • 56
  • 177
  • 295
295
votes
11 answers

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('/') @user.route('//') def show(userId, username=None): pass How can I directly say that…
Noor
  • 18,061
  • 35
  • 123
  • 236
274
votes
9 answers

Redirecting to URL in Flask

I'm new to Python and Flask and I'm trying to do the equivalent of Response.redirect as in C# - ie: redirect to a specific URL - how do I go about this? Here is my code: import os from flask import Flask app = Flask(__name__) @app.route('/') def…
iJade
  • 20,206
  • 52
  • 141
  • 227
269
votes
11 answers

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 was the right choice. So, now I've set up an…
Passiday
  • 5,891
  • 7
  • 37
  • 54
268
votes
14 answers

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 to change the port from 5000 to 80. But when I…
quantumtremor
  • 3,047
  • 2
  • 15
  • 20
258
votes
9 answers

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 table joins along with Inline views. I've…
starwing123
  • 2,693
  • 2
  • 11
  • 7
256
votes
10 answers

Get IP address of visitors using Flask for Python

I'm making a website where users can log on and download files, using the Flask micro-framework (based on Werkzeug) which uses Python (2.6 in my case). I need to get the IP address of users when they log on (for logging purposes). Does anyone know…
Jon Cox
  • 9,614
  • 21
  • 72
  • 113
1
2 3
99 100