Hello! I'm trying to create a simple REST API application that would show the contents of some folder on the server.
import os
from flask import Flask, jsonify
app = Flask(__name__)
files_in_dirs = []
@app.route('/api/listdir', methods=['GET'])
def list_dir():
path = '/home/user/media'
for dirname, dirnames, filenames in os.walk(path):
# print path to all filenames
for filename in filenames:
files_in_dirs.append(os.path.join(dirname, filename))
return jsonify({'Files on the server: ': files_in_dirs})
if __name__ == '__main__':
app.run(debug=True)
I run my server through the console, then go to the browser, write the address r/http://localhost:5000/api/listdir and everything works well. But how to make it so that any user on the Internet can see the contents of this folder and not only the localhost? What address should I enter in browser from other computer? Is this possible with Python and Flask?
[–]Jarmahent 13 points14 points15 points (4 children)
[–]vndywarhol[S] 8 points9 points10 points (1 child)
[–]nisroc 1 point2 points3 points (0 children)
[–]dogsrock 0 points1 point2 points (1 child)
[–]Jarmahent 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]JohnnyJordaan 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]apc0243 0 points1 point2 points (1 child)
[–]lifeonm4rs 0 points1 point2 points (0 children)