Serve static files with Eve

I am running Flask and Eve on the local host at the same time. The Flask application serves static files and queries the Eve application for some data. I want to run only Eve, without a separate Flask application. How can I serve static files with Eve?

+5
source share
3 answers

The best approach would be the / api prefix for all REST APIs. This can be done by adding URL_PREFIX="api" in settings.py.

Performing this when there is a request in /, Eve (Flask) does not return the resource directory, but returns the page as specified in run.py.

To serve static content, add route attributes to run.py, respectively.

 @app.route('/') def index(): return app.send_static_file('index.html') app.run(host="0.0.0.0", debug=True) 
+4
source

Eve is an application for flash drives (a subclass), since the general rule is that everything that works with Flask works with Eve. You can register a project or add new routes.

Also see this answer for a link to a working example: Serving html requests with Eve

+3
source

try setting import_name arg for Eve:

app = Eve(import_name=__name__)

+1
source

Source: https://habr.com/ru/post/1210470/


All Articles