前端文件:
<form enctype="multipart/form-data" action="/uploadFile/" method="post">
<input type="file" name="myfile" />
<br/>
<input type="submit" value="上传"/>
</form>
后端文件
urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^upload.html$', views.upload_file),
]
view.py
PATH = '/home/Image/' # 文件上传默认路径
def upload_file(request):
#pic
PIC = request.FILES.get('myFile')
f = open(os.path.join(PATH, PIC.name), 'wb')
for chunk in PIC.chunks():
f.write(chunk)
f.close()
returnHttpResponse("上传完毕!")