I am trying to do a POST request using tastypie in django.
My Resource looks like below:
class TestResource(ModelResource):
class Meta:
queryset = Test.objects.all()
resource_name = 'test'
serializer = Serializer(formats=['json','xml'])
always_return_data = True
detail_allowed_methods = ['get', 'post', 'put', 'delete']
And I am posting data like below:
import sys
import requests
DATA = {'field1':'posting data', 'field2':'123', 'field3':330303,}
def post(data):
url = 'http://127.0.0.1:8000/api/test/'
logging = {'verbose':sys.stderr}
response = requests.post(url,data=data,config=logging)
print "RESPONSE STATUS", response.status_code
print "RESPONSE HEADERS", response.headers
if __name__=='__main__':
post(DATA)
I am always getting 401, any idea?
What I am doing wrong?
Thanks in advance.
You will need to set
The default authorization implmented by tastypie is
which results in, you guessed it, readonly results, hence it will cause errors.
http://django-tastypie.readthedocs.org/en/latest/tutorial.html
Do take note that it is not the best practice to do that however. There are other methods of Authorizations that can be used.