Serve static files with Eve
Asked Answered
A

3

5

I am running Flask and Eve on localhost at a same time. The Flask app serves static files and makes requests to the Eve app to get some data. I want to run Eve only, without a separate Flask app. How can I serve static files with Eve?

Appointee answered 6/1, 2015 at 12:36 Comment(5)
whats your applicationAshram
my application is simple chat+searching application using angularjs and python eveAppointee
so you need to test your application in localhostAshram
read this python-eve.org/config.htmlAshram
python-eve.org/config.html in this link there is no content how to serve js and css files.Appointee
C
4

A better approach will be to prefix the /api for all REST APIs. This can be done by adding URL_PREFIX="api" in settings.py.

By doing this whenever there is request to /, Eve(Flask) will not return the resource catalog instead returns the page as given in run.py.

To serve static content add route decorators accordingly in run.py,

@app.route('/')
def index():
    return app.send_static_file('index.html')

app.run(host="0.0.0.0", debug=True)
Conceivable answered 16/2, 2015 at 11:7 Comment(1)
I found this worked with just the URL_PREFIX and not the @app.route. Good answer.Chest
E
3

Eve is a Flask application (a subclass) so as a general rule everything that works with Flask works with Eve too. You could register a blueprint, or add new routes.

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

Edlyn answered 6/1, 2015 at 15:49 Comment(1)
you're welcome. Please accept the answer if you feel like it helped you find a solution :)Edlyn
A
1

try set import_name arg for Eve:

app = Eve(import_name=__name__)

Abrahamabrahams answered 25/12, 2016 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.