0

I have a view function defined like this:

@app.route('/blog', defaults={'page': 1})
@app.route('/blog?page=<int:page>')
def posts(page):
...

I goto this link:

http://example.com/blog?page=5

But, no matter what I try, the value of page is always 1.

What am I doing wrong? Using Flask 0.10.1.

4
  • what if you change the order of the decorators? Commented Oct 24, 2014 at 5:47
  • @UkuLoskit I tried that, no difference. Commented Oct 24, 2014 at 5:48
  • 1
    I think you needn't specify the parameter in the url at all, why not use just request.args.get('page') and specify the default value as the optional argument to get. Commented Oct 24, 2014 at 5:50
  • Yes, that works (page = request.args.get('page', default=1, type=int)). Does Flask no longer support multiple routes for a view? Commented Oct 24, 2014 at 6:01

1 Answer 1

2

Routes don't work like that: they never match against querystring arguments. Just match on the path and get page from request.args.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.