-1
app = Flask(__name__,
            static_path='',
            static_url_path=None,
            static_folder='templates/assets',
            template_folder='templates',
            instance_path=None,
            instance_relative_config=False)
app.debug = False




@app.route("/", methods=['GET'])
def index():
    return render_template("index.html")

@app.route('/results/<path:filename>', methods=['GET'])
def serve_static(filename):
    root_dir = os.path.dirname(os.getcwd())
    #for windows too
    return app.send_static_file(os.path.join('results', filename).replace('\\','/'))

What do I do wrong? http://127.0.0.1:5000/assets/result.csv this gives me an error:

Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

user2950593
  • 9,233
  • 15
  • 67
  • 131
  • well, you have the `static_folder` defined as `templates/assets` not as `assets` – Ignacio Vergara Kausel Jan 26 '18 at 11:22
  • @IgnacioVergaraKausel http://127.0.0.1:5000/templates/assets/result.csv doesn't work too – user2950593 Jan 26 '18 at 11:26
  • if `static_folder` defined as `templates/assets`, and you want to get `results.csv` I think you should get `http://127.0.0.1:5000/results/result.csv` (assuming you have a `result.csv` file in `templates/assets` folder on you server) – yeger Jan 26 '18 at 12:45

1 Answers1

1

Might be worth to check what os.path.join('results', filename).replace('\\','/') evaluates to.

Have you tried a (little safer) approach using send_from_directory?

(Didn't check if it actually works):

@app.route('/results/<path:filename>', methods=['GET'])
def serve_static(filename):
    return send_from_directory(os.path.dirname(os.getcwd()), filename)
Igor
  • 2,834
  • 2
  • 26
  • 44