When I try POST or GET methods to the resource URL(127.0.0.1:8000/api/v1/user/login/) Im getting the below error.
Traceback (most recent call last): File "/home/mithu/pipliko/pipliko/load_projects/api.py", line 55, in login self.method_check(self,allowed=['post','get']) File "/home/mithu/pipliko/local/lib/python2.7/site-packages/tastypie/resources.py", line 519, in method_check request_method = request.method.lower() File "/home/mithu/pipliko/local/lib/python2.7/site-packages/tastypie/resources.py", line 186, in getattr raise AttributeError(name) AttributeError: method
my 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 login(self,request,**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);