Thank you Michael this works beautifully.
On Wednesday, March 27, 2013 6:02:04 PM UTC, Michael Merickel wrote:
>
> Renderers are typically responsible for setting the content type on the
> request.response object themselves (if you haven't overridden it already).
> It'd be possible to write a view predicate that you can use next to the
> renderer argument, to make it more declarative.
>
> class ResponseContentTypePredicate(object):
> def __init__(self, config, val):
> self.val = val
>
> def text(self):
> return 'response content-type = %s' % self.val
> phash = text
>
> def __call__(self, context, request):
> if self.val is not None:
> request.response.content_type = self.val
> return True
>
> config.add_view_predicate('response_content_type',
> ResponseContentTypePredicate)
>
> @view_config(..., renderer='foo.mako', response_content_type='text/xml')
> def ...
>
> Anyway, just another option for you. This was written without the docs so
> expect an error somewhere!
>
>
> On Wed, Mar 27, 2013 at 11:56 AM, Tjelvar <[email protected]<javascript:>
> > wrote:
>
>> Jason and Joel - thank you for your suggestions.
>>
>> I managed to get it to work using the suggestion below.
>>
>>
>> On Wednesday, March 27, 2013 1:29:44 PM UTC, Joel Kaiser wrote:
>>
>>> Hi,
>>>
>>> I don't know if its a nice solution, but you can also set the
>>> content-type in your page template:
>>>
>>> <tal:setHeader >
>>> ${setattr(request.response,'**content_type','text/xml')}
>>> </tal:setHeader>
>>>
>>> Joel
>>>
>>>
>>> 2013/3/27 Jason <[email protected]>
>>>
>>>>
>>>>
>>>> On Wednesday, March 27, 2013 5:22:36 AM UTC-4, Tjelvar wrote:
>>>>>
>>>>> Any suggestions on how one can modify the content-type of a response
>>>>> when using multiple @view_config decorators on the same view?
>>>>>
>>>>> E.g.
>>>>>
>>>>> @view_config(accept='text/**html**', renderer='html.pt', ...)
>>>>> @view_config(accept='text/xml'****, renderer='xml.pt', ...)
>>>>> @view_config(accept='**applicati**on/json' renderer='json')
>>>>> def aview(request):
>>>>> return {'a':1]
>>>>>
>>>>>
>>>>> Hi Tjelvar,
>>>> Would you be able to use an event subscriber (BeforeRender?) that would
>>>> change the content-type of the response?
>>>> I do this for an application, but I am using a matchdict parameter to
>>>> determine the response content-type in the subscriber.
>>>>
>>>> --
>>>> Jason
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "pylons-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to pylons-discus...@**googlegroups.com.
>>>> To post to this group, send email to pylons-...@googlegroups.**com.
>>>>
>>>> Visit this group at http://groups.google.com/**
>>>> group/pylons-discuss?hl=en<http://groups.google.com/group/pylons-discuss?hl=en>
>>>> .
>>>> For more options, visit
>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>> .
>>>>
>>>>
>>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "pylons-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.