Answers for "Django forms I cannot save picture file"

0

Django forms I cannot save picture file

def upload_pic(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            m = ExampleModel.objects.get(pk=course_id)
            m.model_pic = form.cleaned_data['image']
            m.save()
            return HttpResponse('image upload success')
    return HttpResponseForbidden('allowed only via POST')
Posted by: Guest on September-19-2020
0

Django forms I cannot save picture file

class ImageUploadForm(forms.Form):
    """Image upload form."""
    image = forms.ImageField()
Posted by: Guest on September-19-2020
0

Django forms I cannot save picture file

<form action="{% url upload_pic %}" method="post" enctype="multipart/form-data">{% csrf_token %}
    <p>
        <input id="id_image" type="file" class="" name="image">
    </p>
    <input type="submit" value="Submit" />
</form>
Posted by: Guest on September-19-2020
0

Django forms I cannot save picture file

class ExampleModel(models.Model):
    model_pic = models.ImageField(upload_to = 'pic_folder/', default = 'pic_folder/None/no-img.jpg')
Posted by: Guest on September-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language