Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-tastypie. Output in JSON to the browser by default

Tags:

I see 'Sorry, not implemented yet. Please append "?format=json" to your URL.'. I need always append string "?format=json". Can I make a output in JSON by default?

Regards, Vitaliy

like image 500
moskrc Avatar asked Dec 27 '11 21:12

moskrc


1 Answers

From the tastypie cookbook, in order to change the default format, you need to override the determine_format() method on your ModelResource:

class MyResource(ModelResource):     ....     def determine_format(self, request):         return 'application/json' 

The above link demonstrates alternative methods of determining output format.

Also, I don't think a valid answer is essentially "You don't need this".

Edit

It appears GregM's answer is probably (I haven't tested it) the most correct with the new version of TastyPie, as per documentation putting the following in your settings.py will restrict the serialization output to json.

 TASTYPIE_DEFAULT_FORMATS = ['json'] 
like image 102
mrmagooey Avatar answered Oct 19 '22 23:10

mrmagooey