Pooja
Pooja

Reputation: 796

Flask url not working

I am working on flask app which has below code in views.py:

@bp.route('/talents/filters', methods=['POST'])
def talents_filters():
    form = TalentFilters()
    if form.validate_on_submit():
        set_filters(form)
    return redirect_back('.home')

@bp.route('/talents/filters/reset<path:uri>')
def talents_filters_reset(uri):
    return session['filters'][uri]

The first url is working fine. But the second one is giving 404 error.

First one works on

http://localhost:5000/admin/talents/filters

For second I am trying url

http://localhost:5000/admin/talents/filters/reset?uri=%2Fadmin%2Ftalents%2F

It is giving 404 NOT FOUND status code. I am completely clueless. Please help.

Upvotes: 1

Views: 1185

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121168

URL query parameters (everything after the ?) are not part of the path. They are not captured by <path:uri>; that parameter expects to find a path element starting with a / instead.

Use:

@bp.route('/talents/filters/reset')
def talents_filters_reset():
    uri = request.args['uri']
    return session['filters'][uri]

instead, where request.args contains all parsed request parameters.

Upvotes: 1

Related Questions