Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 694
hof0w Avatar asked Jun 10 '12 02:06

hof0w


People also ask

How do I create a URL alias?

Create a Web alias on your domainClick DNS settings on the Advanced settings tile. Go to DNS records. Under create new record, click Web alias.

How do you add a URL to a Flask?

The url_for() function is used to build a URL to the specific function dynamically. The first argument is the name of the specified function, and then we can pass any number of keyword argument corresponding to the variable part of the URL.

What is alias name in URL?

URL aliases (e.g., “about-us” instead of “node/9”) are automatically assigned by default, and are what appear in the URL of your individual pages (e.g., http://YOURSITE.berkeley.edu/about-us).


1 Answers

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

@app.route('/')
@app.route('/index')
def index():
    ...
like image 166
FogleBird Avatar answered Nov 03 '22 14:11

FogleBird