pythonurlpyramidroutes

Pyramid: Default values in route pattern


I was wondering:
Is it possible, to provide default values within the pattern of a route configuration?
For example: I have a view that shows a (potentially large) list of files bound to a data set. I want to split up the view in pages, which each page showing 100 files. When the page part in the url pattern is omitted, I want the first page to be shown.
So I'd like to have something like:

config.add_route('show_files', '/show_files/{datasetid}/{page=1})

Is that, or an alternative doable with reasonable effort? I haven't found anything in the route syntax description in the pyramid documentation.

Thanks a lot!


Solution

  • No, but you can use a remainder match to make the page optional, and then decide what page to show in your actual logic.

    http://readthedocs.org/docs/pyramid/en/main/narr/urldispatch.html

    The other option is to simply have your page be a GET variable rather than part of the URL.