-1

I'm trying to serve 2 static files named index.html and main.js in flask. My code is as follows:

from flask import Flask, url_for

app = Flask(__name__)


@app.route('/')
def host_html():
    return url_for('static', filename='index.html')



@app.route('/map.js')
def host_map():
    return url_for('static', filename='map.js')


if __name__ == '__main__':
    app.run()

The output however on the web page is /static/index.html. What am I missing?

PlsBuffMyBrain
  • 177
  • 1
  • 7

1 Answers1

1

url_for function just returns a url, not the actual file. What you want to use in this case is send_from_directory: http://flask.pocoo.org/docs/1.0/api/#flask.send_from_directory

In general, i guess what you really want to do, is to use url_for in i a jinja template, which you return by render_template.

olisch
  • 960
  • 6
  • 11