1
# 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 个参数。有人见过吗?我错了吗?

4

1 回答 1

1

在 sweetpie 版本 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()
于 2013-02-20T21:52:12.513 回答