Django Tastypie版本0.9.13与obj_get有什么问题?

时间:2013-02-20 21:27:01

标签: django tastypie

# views.py
from django.shortcuts import render_to_response
from myapp.api.resources import UserResource


def user_detail(request, username):
    ur = UserResource()
    user = ur.obj_get(username=username)

    # Other things get prepped to go into the context then...

    ur_bundle = ur.build_bundle(obj=user, request=request)
    return render_to_response('myapp/user_detail.html', {
        # Other things here.
       "user_json": ur.serialize(None, ur.full_dehydrate(ur_bundle), 'application/json'),
    })

但是它给出了错误,因为obj_get()需要2个参数。有人见过吗?我错了吗?

1 个答案:

答案 0 :(得分:1)

在tastypie版本0.9.13中,obj_get方法需要参数包。

def obj_get(self, bundle, **kwargs):
    """
    Fetches an individual object on the resource.

    This needs to be implemented at the user level. If the object can not
    be found, this should raise a ``NotFound`` exception.

    ``ModelResource`` includes a full working version specific to Django's
    ``Models``.
    """
    raise NotImplementedError()