Search code examples
pythonflaskjinja2werkzeug

How to have an alias of URL on Python Flask?


I'm using Flask 0.8.

How to have an alias of a URL like this:

@app.route('/')
def index():
    # I want to display as http://localhost/index, BUT, I DON'T WANT TO REDIRECT.
    # KEEP URL with only '/'

@app.route('/index')
def index():
    # Real processing to display /index view

So, why my hope to use an alias because of DRY of processing /index

Someone knew the solution?

thanks pepperists.


Solution

  • This should work. But why do you want two URL's to display the same thing?

    @app.route('/')
    @app.route('/index')
    def index():
        ...