Serving Angular front end with Flask does not render images Serving Angular front end with Flask does not render images flask flask

Serving Angular front end with Flask does not render images


In server.py, add a static_proxy to ensure that supporting files are served.

from flask import Flask, send_from_directoryapp = Flask(__name__)@app.route('/<path:path>', methods=['GET'])def static_proxy(path):  return send_from_directory('./', path)@app.route('/')def root():  return send_from_directory('./', 'index.html')if __name__ == '__main__':  # This is used when running locally only. When deploying use a webserver process   # such as Gunicorn to serve the app.  app.run(host='127.0.0.1', port=8080, debug=True)@app.errorhandler(500)def server_error(e):  return 'An internal error occurred [main.py] %s' % e, 500

Additional resource

Python (Flask) serving Angular project's index.html file

Extra note from asker

In order to be able to make requests from the Flask server serving the angular front-end to itself, in app.run() you must also set threaded=True.