This is a question about uploading an image.

Asked 2 years ago, Updated 2 years ago, 78 views

Hello. I keep asking questions. If you select an image and press the file upload button, that screen comes out and you can't move to the next screen. model.py

class image(models.Model):
    image1=models.ImageField(upload_to='pic_folder/%Y/%m/%d')
    image2=models.ImageField(upload_to='pic_folder/%Y/%m/%d')
    image3=models.ImageField(upload_to='pic_folder/%Y/%m/%d')

    class Meta:
        db_table="tableau_image"

foms.py

class imageForm(forms.ModelForm):
    class Meta:
        model = image
        fields = ('image1','image2','image3',)


views.py

   def index(request):
     if request.method == "POST":
        upimage=imageForm(request.POST, request.FILES)
        if upimage.is_valid():
            Tableau=image()
            Tableau.image1 = upimage.cleaned_data["image1"]
            Tableau.image2 = upimage.cleaned_data["image2"]
            Tableau.image3 = upimage.cleaned_data["image3"]
            Tableau.save()
            return HttpResponseRedirect('/result/')
    else:
        upimage = imageForm()
    return render(request, 'upload.html', {'upimage': upimage})

I've made it into something.

django

2022-09-22 21:52

1 Answers

When creating a form tag in upload.html

<form method='POST' action = "..." enctype="multipart/form-data">

Did you specify the enct type like this?


2022-09-22 21:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.