我的数据库正在使用带路径的图片名称进行更新,但图片尚未上传到指定的文件夹中。我是Django的新手,如果我的编码错误,请帮忙。下面是我的代码:
Model.py:
class MasterBank(models.Model):
bankid = models.BigIntegerField(primary_key=True,blank=True)
bankname = models.CharField(max_length=255, blank=True)
banklogourl = models.ImageField(upload_to ='images/', blank=True)
views.py :
class imageUpload(APIView):
def post(self,request):
checkReq = request.FILES['banklogourl']
m = MasterBank.objects.get(pk=1)
m.banklogourl = checkReq
m.save()
return HttpResponse('image upload success')
Urls:
url(r'^imageupload/$', views.imageUpload.as_view(), name="imageUpload"),
答案 0 :(得分:0)
应在settings.py
中指定媒体路径MEDIA_ROOT = normpath(加入(SITE_ROOT,'媒体')) MEDIA_URL =' / media /'