Solved this with the help of raydeo (Michael Merickel) and mcdonc (Chris 
McDonoug) from #pyramid IRC.

Michael gives several suggestions, the one I found the most to my liking is 
to add a decorator:

    def set_content_type(content_type):
        def view_decorator(view):
            def wrapped_view(*args, **kwargs):
                resp = view(*args, **kwargs)
                resp.content_type = content_type
                return resp
            return wrapped_view
        return view_decorator

    @view_config(accept="application/xml", renderer='template.xml.pt', 
decorator=set_content_type('application/xml'))
    @view_config(accept="text/html", renderer='template.html.pt', 
decorator=set_content_type('text/html'))
    def myview(...):
        ...

Thanks to all involved!

On Wednesday, April 16, 2014 6:07:57 PM UTC+1, Lie Ryan wrote:
>
> I have a single view configured to be rendered with multiple renderers 
> based on Accept header set:
>
>     @view_config(accept="application/xml", renderer='template.xml.pt')
>     @view_config(accept="application/json", renderer='template.json.pt')
>     @view_config(accept="text/html", renderer='template.html.pt')
>     def myview():
>         ...
>
> How do I set the Content-Type for the response? At the moment both views 
> gets rendered as text/html.
>
> I know that I can set request.response_content_type = '...', but that 
> still leaves me with the problem of detecting which view_config() line is 
> actually used for the current page.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to