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!
You're probably content with this answer, but another option is to use multiple routes that dispatch to the same view.
config.add_route('show_files', '/show_files/{datasetid}')
config.add_route('show_files:page', '/show_files/{datasetid}/{page}')
@view_config(route_name='show_files')
@view_config(route_name='show_files:page')
def show_files_view(request):
page = request.matchdict.get('page', '1')
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/master/narr/urldispatch.html
The other option is to simply have your page be a GET variable rather than part of the URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With