mos*_*krc 24 django json tastypie
我看到'对不起,还没有实现.请将"?format = json"附加到您的网址.' 我需要总是附加字符串"?format = json".我可以默认使用JSON输出吗?
此致,Vitaliy
mrm*_*oey 41
从tastypie cookbook中,为了更改默认格式,您需要覆盖ModelResource上的determine_format()方法:
class MyResource(ModelResource):
....
def determine_format(self, request):
return 'application/json'
Run Code Online (Sandbox Code Playgroud)
上面的链接演示了确定输出格式的替代方法.
另外,我认为有效答案基本上不是"你不需要这个".
编辑
看来GregM的答案很可能(我还没有测试过)使用新版本的TastyPie最正确,因为根据文档将以下内容settings.py
限制在你的序列化输出到json.
TASTYPIE_DEFAULT_FORMATS = ['json']
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6633 次 |
最近记录: |