标签:视图 else res ons 模板 value val put views
url:
#上传文件 url(r‘^upfile/$‘,views.upfile), url(r‘^savefile/$‘,views.savefile),
视图:
def upfile(request): return render(request,‘myApp/upfile.html‘) def savefile(request): if request.method == "POST": f = request.FILES[‘file‘] filePath = os.path.join(settings.MEDIA_ROOT,f.name) with open(filePath,‘wb‘) as fp: for info in f.chunks(): fp.write(info) return HttpResponse("上传成功") else: return HttpResponse("上传失败")
模板:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>上传文件</title> </head> <body> <form action="/sunck/savefile/" method="post" enctype="multipart/form-data"> {% csrf_token %} <input type="file" name="file"> <input type="submit" value="上传"> </form> </body> </html>
setting
MEDIA_ROOT = os.path.join(BASE_DIR,r‘static\upfile‘)
标签:视图 else res ons 模板 value val put views
原文地址:https://www.cnblogs.com/hooo-1102/p/11971348.html