Hosting static files

231 views
Skip to first unread message

Harish Gowda

unread,
Sep 12, 2013, 2:49:33 PM9/12/13
to pytho...@googlegroups.com

Along with the API's. I also want to host some static files which will provide more information about the API's exposed. How to accomplish that?
Since it is a subclass of Flask. I tried:

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


It returned a 404.

Bryan Cattle

unread,
Sep 12, 2013, 2:57:39 PM9/12/13
to pytho...@googlegroups.com
I don't know specifically why that wouldn't work, but a better approach is probably to put any non-REST stuff in a separate Flask app. You can then use wekzeug DispatcherMiddleware to direct requests to both, based on the url or a subdomain. 

application = DispatcherMiddleware(eve_app, {
    '/static':     static_app
})



On Thu, Sep 12, 2013 at 11:56 AM, Bryan Cattle <bryan....@gmail.com> wrote:
I don't know specifically why that wouldn't work, but a better approach is probably to put any non-REST stuff in a separate Flask app. You can then use wekzeug DispatcherMiddleware to direct requests to both, based on the url or a subdomain. 

application = DispatcherMiddleware(eve_app, {
    '/static':     static_app
})



--
You received this message because you are subscribed to the Google Groups "Eve REST API Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-eve+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Message has been deleted

Harish Gowda

unread,
Sep 12, 2013, 3:07:40 PM9/12/13
to pytho...@googlegroups.com
Thanks. Actually, I'm writing a javascript front end app using Ember.js which will feed on the API. I want to keep them together for time being,  Because I already have flask and js code working together.  I want to take up the separation piece later.

Bryan Cattle

unread,
Sep 12, 2013, 3:36:55 PM9/12/13
to pytho...@googlegroups.com
Well they are still together - the DispatcherMiddleware combines two Flask (really WSGI) app classes into one. You then run the result (application above) using a single server program (Apache, Gunicorn) on a single port. 


Harish Gowda

unread,
Sep 12, 2013, 11:06:54 PM9/12/13
to pytho...@googlegroups.com
So it is not possible configure static html within eve?

Nicola Iarocci

unread,
Sep 13, 2013, 1:36:51 AM9/13/13
to pytho...@googlegroups.com
Not within Eve, not at the moment at least. Besides Bryan's example, another one would be the very cool Eve-Docs application: https://github.com/charlesflynn/eve-docs.

Nicola

safar...@gmail.com

unread,
Sep 16, 2013, 10:34:42 AM9/16/13
to pytho...@googlegroups.com
Hi, I am new to this too and am in the transition from bottle.py/self written stuff/Sencha ExtJs to Eve/Sencha ExtJs .
I am serving my static files withouth problems through Eve/Flask. I have not bserved any side effects. At least not til now.

#!/bin/env python2.7
from eve import Eve
from flask import redirect,send_from_directory,render_template
import os

PWD = os.environ.get("PWD")

# set folder for static data
static_folder=os.path.join(PWD,"static")

# set path for settings file
settings=os.path.join(PWD,"settings.py")

app = Eve(settings=settings,static_folder=static_folder)

# get servername and port from settings file
serverdata = app.config["SERVER_NAME"].split(":")
host = serverdata[0]
port = serverdata[1]

@app.route('/favicon.ico')
def favicon():
  return send_from_directory(os.path.join(static_folder,"images"), "openterm.ico")

@app.route('/index.html')
@app.route('/')
def index_html():
  return send_from_directory(static_folder, "index.html")

def main():
    app.run(host=host,port=int(port),debug=True)

if __name__ == "__main__":
    main()

 hth
Reply all
Reply to author
Forward
0 new messages