model.py
class Image(models.Model): 名称= models.CharField(max_length = 30) 图片=模型。ImageField(upload_to ='照片')
view.py def image_create(request,template_name ='photo / form.html'): 形式= ImageForm(request.POST或无,request.FILES或无) 如果form.is_valid(): form.save()
return render(request, template_name, {'form':form})
upload.html
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
<img src="{{ image.image.url }}" alt="ko" width="500px" height="500 px" />