I'm currently working on the project that use Android for client and Django for web server. I decided to use piston-django to create REST API authentication and I've follow this instruction: What is the right way to write a django-piston client? and write my own handler (api/handlers.py) to create and return ApiKey like this:
class ApiKeyhandler(Basehandler):
model = ApiKey
allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')
fields = ('user', 'keys')
def create(self, request):
attrs = self.flatten_dict(request.POST)
if self.exists(**attrs):
return rc.DUPLICATE_ENTRY
else:
apikey = ApiKey(user=request.user)
apikey.save()
return apikey
and in urls.py I use HttpBasicAuthentication for this handler:
auth = HttpBasicAuthentication(realm="Authentication API")
apikey = Resource(handler=ApiKeyHandler, authentication=auth)
but when I test it with http://hurl.it
This is the response from POST method
Can anyone tell me how to write the complete code for this question or any suggestion on this problem?