Skip to content

url_for: Allow overriding default values #2456

Answered by davidism
NickVeld asked this question in Q&A
Discussion options

You must be logged in to vote

This comes from a misunderstanding of how defaults works in Werkzeug's router. From the docs for werkzeug.routing.Rule:

`defaults`
    An optional dict with defaults for other rules with the same endpoint.
    This is a bit tricky but useful if you want to have unique URLs::

        url_map = Map([
            Rule('/all/', defaults={'page': 1}, endpoint='all_entries'),
            Rule('/all/page/<int:page>', endpoint='all_entries')
        ])

    If a user now visits ``http://example.com/all/page/1`` they will be
    redirected to ``http://example.com/all/``.  If `redirect_defaults` is
    disabled on the `Map` instance this will only affect the URL
    generation.

So you would use d…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@NickVeld
Comment options

Comment options

You must be logged in to vote
4 replies
@davidism
Comment options

@NickVeld
Comment options

@NickVeld
Comment options

@NickVeld
Comment options

Answer selected by davidism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants