I want to write a rest method without model so that I can send a csv file using python requests module. This csv file should be remotely accessed from the server.
For example - I have logged in to my project using requests and get the cookies and headers so that I can pass it to the following requests method..
files = {'file': open('test.csv', 'rb')}
response = requests.post(url, files=files, headers=api_headers,
cookies=api_cookies)
So this url should be : call for that rest method.
views.py file :
class FileUploadView(APIView):
parser_classes = (FileUploadParser,)
def post(self, request, format=None):
csvfile = request.data['file']
#reader = csv.DictReader(csvfile)
#for r in reader:
#print(r)
return Response(status=204)
Just to note - I am sending a csv file using requests module.
Can anyone please help me on how to write this rest method?
Normal django view
UPDATE
Then
This would do the trick for you. http://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser