它實際上是工作,現在使用Python的請求模塊
生病把代碼爲所有感興趣...
Django的服務器...
urls.py
...
url(r'^list/$', 'dataports.views.list', name='list'),
...
views.py
@csrf_exempt
def list(request):
# Handle file upload
if request.method == 'POST':
print "upload file----------------------------------------------"
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
print "otra vez.. es valido"
print request.FILES
newdoc = Jobpart(
partfile = request.FILES['docfile']
)
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('dataports.views.list'))
else:
#print "nooooupload file----------------------------------------------"
form = DocumentForm() # A empty, unbound form
# Render list page with the documents and the form
return render_to_response(
'data_templates/list.html',
{'form': form},
context_instance=RequestContext(request)
)
list.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Minimal Django File Upload Example</title>
</head>
<body>
<!-- Upload form. Note enctype attribute! -->
<form action="{% url "list" %}" method="post" enctype="multipart/form-data">
<p>
{{ form.docfile }}
</p>
<p><input type="submit" value="Upload" /></p>
</form>
</body>
</html>
現在在客戶端。
client.py
import requests
url = "http://localhost:8000/list/"
response = requests.post(url,files={'docfile': open('test.txt','rb')})
現在你可以添加一些安全和東西。但它其實是一個很簡單的例子..
謝謝大家!!!!