On Fri, 2012-05-11 at 02:18 -0700, Graham Klyne wrote: > I'm trying to use view_config accept parameters for HTTP content-type > negotiation, e.g.
I can provide a partial answer ...
> I am assuming that this is what the accept parameter is provided for,
> as I can't see any other useful purpose, but maybe that's a
> misunderstanding on my part.
Your understanding is correct.
> Using the above structure, I am running into a couple of issues:
Yes, I can confirm that, the match is case-sensitive.
> (b) I can't see any way to create a catch-all match, to be used when
> none of the view_config options *with* accept parameters are matched.
The Pyramid URL dispatch mechanism is basically "An ordered set of
patterns is checked one-by-one" so, if you simply remove the
specialising match parameter, you're left with a catch-all which, to be
effective, needs to appear last in the batting order:
@view_config(route_name='service', request_method='GET')
def service_default(request):
return Response("Default\n")
> (c) The matching doesn't honour the q= values generated by browsers;
> e.g. I have Firefox generating:
>
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8,application/rdf+xml;q=0.93,text/rdf+n3;q=0.5
>
> but I'm actually seeing the HTML version returned.
>
> Is there something important I'm overlooking here?
You just need to set the content-type of the response:
@view_config(route_name='service', request_method='GET',
accept='text/turtle')
def service_turtle(request):
return Response("TTL\n", content_type="text/turtle")
--
Graham Higgins
http://bel-epa.com/gjh/
signature.asc
Description: This is a digitally signed message part
