url structure and form posts with Flask url structure and form posts with Flask flask flask

url structure and form posts with Flask


The query parameters are not included as part of the route matching, nor are they injected into function arguments. Only the matched URL portions are injected. What you're looking for is request.args (GET query parameters), request.form (POST) or request.values (combined).

You could do something like this if you wanted to support both:

@app.route('/search/<location>')def search(location=None):    location = location or request.args.get('location')    # perform search

Though, assuming you may want to search on other parameters, probably the best way to do it would be closer to:

def _search(location=None,other_param=None):    # perform search@app.route('/search')def search_custom():    location = request.args.get('location')    # ... get other params too ...    return _search(location=location, other params ... )@app.route('/search/<location>')def search_location(location):    return _search(location=location)

And so forth.