Flask URL Route: Route Several URLs to the same function


I am working with Flask 0.9.

Now I want to route three urls to the same function:

/item/<int:appitemid>/<anything can be here>

The <anything can be here> part will never be used in the function.

I have to copy the same function twice to achieve this goal:

def show_item(appitemid):

def show_item(appitemid, anythingcanbehere):

Will there be a better solution?


Why not just use a parameter that can potentially be empty, with a default value of None?

def show_item(appitemid, anythingcanbehere=None):

Answered By – Amber

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published