1
我試圖使用請求將XML文件發送到django視圖。我認爲,該文件正在做派:如何在django中通過POST接收XML文件
headers = {'Content-Type': 'application/xml'}
response = requests.post('http://localhost:8000/file/', data=file, headers=headers)
鑑於我:
class ReceiveFile(TemplateView):
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
print request.read()
return HttpResponse('')
那麼,如何讀文件在這裏查看並再次將其保存爲XML? request.read()爲我提供了發送文件的路徑。
Best,Blake
嘗試['request.body'(https://docs.djangoproject.com/en/1.8/ref/request-response/#django。 http.HttpRequest.body) – Alasdair
你不應該在'dispatch'中這樣做,而是在'post'中。 –
request.body給我的輸出與request.read()相同,這是發送文件的文件的路徑 –