django实现任意路径下文件上传

前端文件:


后端文件

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("上传完毕!") 

 

你可能感兴趣的:(Python)