How force requests post xml to django's request.FILES but not request.POST?

I'm using requests to post xml file to django 1.7b4, seems requests would try convert file content to string, if convert successfully then post it to request.POST, or failed to requist.FILES. but, how force it always post to request.FILES?

Here is my code:

f = open(full_name, 'rb')
files = {'file': f}                    
res = requests.post(url, files=files, data={'filename':filename})
f.close()

and ugly view function:

if 'file' in request.FILES:
    log_tree = etree.parse(request.FILES['file'])
elif 'file' in request.POST:
    log_tree = etree.fromstring(request.POST['file'])

THX!

链接地址: http://www.djcxy.com/p/56558.html

上一篇: 无法在HttpResponseRedirect中传递参数

下一篇: 如何强制请求xml后django的request.FILES但不request.POST?