Flask is a versatile, light-weight web-development framework constructed utilizing python. A Flask utility is a Python script that runs on an internet server, which listens to HTTP requests and returns responses. It’s designed for easy and quicker improvement. On this article we’ll focus on how can we Learn information with out Saving them in Flask, we will even confirm that the file uploaded efficiently or not.
Required Module
Set up Flask by operating the pip command in your terminal.
pip set up Flask
Implementation to Add and Learn the CSV File in Flask Software
Right here on this Flask utility, we’re making a folder named ‘Read_File’ to learn our information. Create a Digital surroundings, After making the digital surroundings we’ll create one templates folder during which we’ll write our HTML half and we additionally create the app.py file during which we’ll write our principal a part of the code in Flask Python.
File Construction:
index.html
On this instance, we’ll function the operation of the learn file with out saving it within the Flask.
HTML
|
Output:
app.py
On this instance, the Flask utility has an endpoint on the root URL /. The endpoint will be accessed through the GET and POST strategies. When a consumer submits the shape with a picture file, the file is uploaded to the server through the POST technique, and its content material is learn utilizing the request.information.get(“file”) technique. The content material of the file is then encoded as a base64 string and included because the src attribute of an HTML img tag. This permits the picture to be displayed within the browser with out saving it to the server. When the endpoint is accessed through the GET technique, the index.html template is returned, which accommodates the shape for importing the file.
Python
|
Output: