Skip to content

Instantly share code, notes, and snippets.

@oscherler
Created April 26, 2011 18:34
Show Gist options
  • Save oscherler/942816 to your computer and use it in GitHub Desktop.
Save oscherler/942816 to your computer and use it in GitHub Desktop.
Trailing slash problem with Flask application dispatching
from werkzeug.wsgi import DispatcherMiddleware
from flask import Flask
from sub_app import app as subapp
app = Flask( __name__ )
# dispatch by path
app.wsgi_app = DispatcherMiddleware( app.wsgi_app, {
'/sub': subapp.wsgi_app
} )
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run( debug = True )
from flask import Flask
app = Flask( __name__ )
@app.route('/')
def hello_moon():
return '''<html><body>Hello, Moon! <img src="static/moon.gif"></body></html>'''
if __name__ == '__main__':
app.run()
@oscherler
Copy link
Author

Put an image moon.gif in sub_app/static/.

Run python mount.py.

@AlexJoz
Copy link

AlexJoz commented Apr 14, 2019

@oscherler do you have solution to avoid this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment