List of files in a folder Flask python

Source code

[sourcecode] from flask import Flask
from flask import jsonify
import os

## create new app
app = Flask(__name__)
#lets create new route
@app.route(‘/’)
#now we will create a new function
def dir():
#this function will fetch all items in a foder/directory
all = os.listdir(‘templates’)
return jsonify(all)

if __name__ == "__main__":
app.run(debug=True, port=8080)
#Let run over app. I am using port 8080. by default it is 5000.
[/sourcecode]

List of files in a folder Flask python

End Notes:

In this tutorial we have learnt to make a simple python flask web app. We have used python core function get list of all files in a folder / directory.

you can find github link here

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: