django forms i cannot save picture file

Solutions on MaxInterview for django forms i cannot save picture file by the best coders in the world

showing results for - "django forms i cannot save picture file"
Matthieu
20 Nov 2020
1def upload_pic(request):
2    if request.method == 'POST':
3        form = ImageUploadForm(request.POST, request.FILES)
4        if form.is_valid():
5            m = ExampleModel.objects.get(pk=course_id)
6            m.model_pic = form.cleaned_data['image']
7            m.save()
8            return HttpResponse('image upload success')
9    return HttpResponseForbidden('allowed only via POST')
Samuel
26 Sep 2018
1<form action="{% url upload_pic %}" method="post" enctype="multipart/form-data">{% csrf_token %}
2    <p>
3        <input id="id_image" type="file" class="" name="image">
4    </p>
5    <input type="submit" value="Submit" />
6</form>
Martina
04 Aug 2016
1class ExampleModel(models.Model):
2    model_pic = models.ImageField(upload_to = 'pic_folder/', default = 'pic_folder/None/no-img.jpg')
Benjamin
07 Aug 2020
1class ImageUploadForm(forms.Form):
2    """Image upload form."""
3    image = forms.ImageField()