标签:path value class roo 图片上传 name ase 后台管理 ipa
pic=models.ImageField(upload_to=‘cars/‘)
pip install Pillow==3.4.1
MEDIA_ROOT=os.path.join(BASE_DIR,"static/media")
<html> <head> <title>文件上传</title> </head> <body> <form method="post" action="upload/" enctype="multipart/form-data"> <input type="text" name="title"><br> <input type="file" name="pic"/><br> <input type="submit" value="上传"> </form> </body> </html>
from django.conf import settings
def upload(request):
if request.method == "POST":
f1 = request.FILES[‘pic‘]
fname = ‘%s/cars/%s‘ % (settings.MEDIA_ROOT,f1.name)
with open(fname, ‘w‘) as pic:
for c in f1.chunks():
pic.write(c)
return HttpResponse("ok")
else:
return HttpResponse("error")
标签:path value class roo 图片上传 name ase 后台管理 ipa
原文地址:https://www.cnblogs.com/alexzhang92/p/9529766.html