emmett icon indicating copy to clipboard operation
emmett copied to clipboard

Routing with conditional parameter

Open josejachuf opened this issue 6 years ago • 5 comments

Hi @gi0baro . The following works fine (for docs)

@mymodule.route("/profile(/<int:user_id>)?")
def profile(user_id):
    if user_id:
        # get requested user
    else:
        # load current logged user profile

But if I want to use it in the home of the module, it fails:

@mymodule.route("/(<int:user_id>)?")
def index(user_id):
    if user_id:
        # get requested user
    else:
        # load current logged user profile

http://127.0.0.1:8000/mymodule/ or http://127.0.0.1:8000/mymodule/1 I get Resource not found

Jose

josejachuf avatar Oct 27 '18 03:10 josejachuf

@mymodule.route("(/<int:user_id>)?")
def index(user_id):
    if user_id:
        # get requested user
    else:
        # load current logged user profile

tweenietomatoes avatar Oct 27 '18 03:10 tweenietomatoes

Thanks @tweenietomatoes, but I still get Resource not found

josejachuf avatar Oct 27 '18 16:10 josejachuf

@josejachuf this is probably a bug regarding conditional parameters and first component of the route url. I will need to inspect this. Will update you.

gi0baro avatar Oct 28 '18 22:10 gi0baro

hi @gi0baro Is this bug resolved?

gaytomycode avatar Jan 15 '24 08:01 gaytomycode

@gaytomycode this was reported before 2.0, it needs to be verified

gi0baro avatar Jan 15 '24 09:01 gi0baro