Search code examples
pythonflaskviewurl-routingdynamic-url

Extra parameter in view function Flask


I was trying to read documentation on Class Based Views and I stumbled upon something that has me scratching my head.

@app.route('/users/')
def show_users(page):
    users = User.query.all()
    return render_template('users.html', users=users)

The show_users function takes a parameter 'page', but there doesn't seem to be a <variable rule> for <page>, so I'm stumped as to how such a view would work without a missing parameter exception. Is this because of the trailing slash in the url, or is this something else? If someone could provide some documentation on this pattern it would be much appreciated as so far I have not found anything.


Solution

  • That might be an error in the documentation. But it's not really important because in the end that code is not used. The docs just consider that piece of code as an example to be refactored into a class-based view.