首页 文章

Tastypie resources.py属性错误 . request.method.lower()

提问于
浏览
0

当我尝试POST或GET方法到资源URL(127.0.0.1:8000/api/v1/user/login/)时,我得到以下错误 .

回溯(最近一次调用最后一次):文件"/home/mithu/pipliko/pipliko/load_projects/api.py",第55行,在登录self.method_check(self,allowed = ['post','get'])文件"/home/mithu/pipliko/local/lib/python2.7/site-packages/tastypie/resources.py",第519行,在method_check中request_method = request.method.lower()文件"/home/mithu/pipliko/local/lib/python2.7/site-packages/tastypie/resources.py",第186行,在 getattr 中引发AttributeError(name)AttributeError:方法

我的api.py

def prepend_urls(self):

return [
        url(r"^(?P<users>%s)/login%s$" %
            (self._meta.resource_name, trailing_slash()),
            self.wrap_view('login'), name="api_login"),
        url(r'^(?P<users>%s)/logout%s$' %
            (self._meta.resource_name, trailing_slash()),
            self.wrap_view('logout'), name='api_logout'),
    ]

def登录(自我,请求,** kwargs):

try:
    print request.method
    self.method_check(self,allowed=['post','get'])
except Exception,e:
    print traceback.format_exc()
    #or
    print sys.exc_info()[0]
data = self.deserialize(request,request.raw_post_data,format = request.META.get('CONTENT_TYPE', 'application/json'))
username = data.get('username','')
password = data.get('password','')
authenticKey = authenticate(username = username,password = password)
if authenticKey:
    if authenticKey.is_active:
        login(request,authenticKey)
        return self.create_response(request,{'success':False, 'user':{'id':user.id}})
    else:
        return self.create_response(request,{'success':False,'reason':'Account disabled'},HttpForbidden);
else:
    return self.create_response(request,{'success':False,'reason':'Wrong credentials'},HttpUnauthorized);

1 回答

相关问题