Mike Orr wrote: > On Tue, Sep 22, 2009 at 8:06 PM, Jonathan Vanasco <jonat...@findmeon.com> > wrote: >> by default it sets response.content_type to "application/json" >> >> is there a way to override this? >> if not , could I request this in a future version of pylons ? >> >> though testing, i discovered that a lot of browsers will 'download' >> application/json files if you hit them directly -- ie, they won't >> render in the browser, they'll just save to disk. >> >> the same browsers will render "text/javascript" files fine. >> >> i've got some custom code that lets me dev stuff, but something built >> into pylons would probably be useful for others. > > I don't quite grok decorators, but it looks like it would have to be a > separate function. The signature is jsonify(func, *args, **kw), so > there's no place to add a content-type argument.
You could use a method which binds the content type into the scope of the jsonfiy decorator. You effectively have a closure, def jsonify(content_type='application/json'): def jsonify_decorator(fn, *args, **kwars): response.headers['content_type'] = content_type # implementation of jsonify goes in here return simplejson.dumps(result) return jsonify_decorator This could also be used to pass in the encoding function into jsonify, so users can specify an alternate to simplejson. When using the decorator you'd specify @jsonify(content_type='text/plain') def foo_method(): pass or @jsonfiy def bar_method(): pass - Shailesh --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---