Skip to content
Advertisement

Tag: flask

Flask POST request is causing server to crash

I am trying to make a simple api in Flask, the first step being getting the POST json data. (I just want to print it for now) This is my code and when I request /api with json data, it returns a 500 error. Any thoughts on why this is happening? The curl command: body.json: Answer First what you want

How do I get the user agent with Flask?

I’m trying to get access to the user agent with Flask, but I either can’t find the documentation on it, or it doesn’t tell me. Answer You can also use the request.user_agent object which contains the following attributes which are created based on the useragent string: platform (windows, linux, macos, etc.) browser (chrome, firefox, msie, etc.) version language string (==

Create dynamic URLs in Flask with url_for()

Half of my Flask routes requires a variable say, /<variable>/add or /<variable>/remove. How do I create links to those locations? url_for() takes one argument for the function to route to but I can’t add arguments? Answer It takes keyword arguments for the variables: The flask-server would have functions:

Using Python, getting the name of files in a zip archive

I have several very large zip files available to download on a website. I am using Flask microframework (based on Werkzeug) which uses Python. Is there a way to show the contents of a zip file (i.e. file and folder names) – to someone on a webpage – without actually downloading it? As in doing the working out server side.

Advertisement