How to serve static files in Flask

The preferred method is to use NGINX or another web server to serve static files; they’ll be able to do it more efficiently than Flask. However, you can use send_from_directory to send files from a directory, which can be pretty convenient in some situations: Alternatively, you could use app.send_file or app.send_static_file, but this is highly … Read more

Trying to run Flask app gives “Address already in use”

It means there’s another service’s using that port (8080 in this case). Maybe because you forgot close another running Flask app and it’s using 8080 port. However, you could change the port you’re using, for example change it to 4444 like this: But anyways, I think you’d like to know which program is using that … Read more

How does ajax work with python?

Usually, ajax handler on your server should return XML or JSON (I think JSON is better) with the data it needs. So, after getting info from the handler, dump(cast) it into a JSON object and return to client. On client, JavaScript receives this JSON, and after that should dynamically create html elements and insert them … Read more

In Flask, what is “request.args” and how is it used?

According to the flask.Request.args documents. flask.Request.argsA MultiDict with the parsed contents of the query string. (The part in the URL after the question mark). So the args.get() is method get() for MultiDict, whose prototype is as follows: In newer version of flask (v1.0.x and v1.1.x), flask.Request.args is an ImmutableMultiDict(an immutable MultiDict), so the prototype and specific method above are still valid.

In Flask, what is “request.args” and how is it used?

According to the flask.Request.args documents. flask.Request.argsA MultiDict with the parsed contents of the query string. (The part in the URL after the question mark). So the args.get() is method get() for MultiDict, whose prototype is as follows: In newer version of flask (v1.0.x and v1.1.x), flask.Request.args is an ImmutableMultiDict(an immutable MultiDict), so the prototype and specific method above are still valid.

Where do I get a SECRET_KEY for Flask?

The secret key is needed to keep the client-side sessions secure. You can generate some random key as below: Just take that key and copy/paste it into your config file See Sessions documentation