Based on the discussion on this site, I implemented the following solution:
from pyramid.request import Request as OldRequest class Request(OldRequest): def route_url(self, route_name, *elements, **kw): qs = kw.get('_query', {}) if 'hid' in qs: raise Exception('hid exists in query string') qs['hid'] = 1337 kw['_query'] = qs return self.route_without_hid(route_name, *elements, **kw) def route_url_without_hid(self, route_name, *elements, **kw): return super(Request, self).route_url(route_name, *elements, **kw)
and also leaves it possible to create URLs that do not have hidden objects.
source share