List of files in a folder Flask python
Source code
[sourcecode] from flask import Flaskfrom 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