标签:使用 rom djang ilo 图片上传 包含 model 提交 pos
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")
参考:http://blog.csdn.net/sxingming/article/details/52098811
标签:使用 rom djang ilo 图片上传 包含 model 提交 pos
原文地址:http://www.cnblogs.com/DarrenChan/p/7903850.html