librelist archives

« back to archive

Chaining Apps

Chaining Apps

From:
Florian Ludwig
Date:
2011-02-15 @ 13:22
Hi,

is it possible to mount on app into another flask app?

Here an example

<<<CODE
from flask import Flask

app = Flask(__name__)
@app.route('/')
def hello_world():
    return "Hello World!"

app2 = Flask('second app')
@app2.route('/')
def foo():
    return "Hi World"

app.add_url_rule('/c', None, app2)


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

So Going to /c would give you "Hi World"

Is this possible with vanilla flask? If not any thoughts what I should
respect when implementing something like that?

Thank you in advance,
 Florian


-- 
Florian Ludwig <dino@phidev.org>

Re: [flask] Chaining Apps

From:
Armin Ronacher
Date:
2011-02-15 @ 17:03
Hi,

On 2/15/11 2:22 PM, Florian Ludwig wrote:
> is it possible to mount on app into another flask app?
No, because it's not clear what information would have to be shared and 
what not (think config, session, cookies etc.).  However you can nicely 
mount them into a new WSGI application by using 
werkzeug.wsgi.DispatcherMiddleware:

   from werkzeug.wsgi import DispatcherMiddleware
   from app1 import app as app1
   from app2 import app as app2

   app = DispatcherMiddleware(app1, {
     '/app2':  app2
   })


Regards,
Armin