custom view params

17 views
Skip to first unread message

Eric Lemoine

unread,
May 6, 2012, 10:18:56 AM5/6/12
to pylons-...@googlegroups.com
Hi

I'd like to be able to set custom config parameters in my views, and read these parameters from request objects. Is this at all possible?

For example:

@view_config(route_name='a_route', renderer='a_renderer', custom_param='some_value')
def v(request)
     return {}


Thanks.


--
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.l...@camptocamp.com
http://www.camptocamp.com

Michael Merickel

unread,
May 6, 2012, 12:50:38 PM5/6/12
to pylons-...@googlegroups.com
Do custom predicates solve your problem?

def extra_params(*params):
def _predicate(context, request):
request.extra_params = params
return True

@view_config(route_name='a_route', renderer='a_renderer',
custom_predicates=[extra_params('some_param')])
def v(request)
params = request.extra_params
return {}

If not, view_config also supports a few other constructs for wrapping
views (such as decorator).
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

Eric Lemoine

unread,
May 6, 2012, 12:53:13 PM5/6/12
to pylons-...@googlegroups.com
On Sun, May 6, 2012 at 6:50 PM, Michael Merickel <mmer...@gmail.com> wrote:
> Do custom predicates solve your problem?
>
> def extra_params(*params):
>    def _predicate(context, request):
>        request.extra_params = params
>        return True
>
> @view_config(route_name='a_route', renderer='a_renderer',
> custom_predicates=[extra_params('some_param')])
> def v(request)
>    params = request.extra_params
>    return {}
>
> If not, view_config also supports a few other constructs for wrapping
> views (such as decorator).

Thanks for the suggestions. I'll look into more detail.
Reply all
Reply to author
Forward
0 new messages