[Django]-Image is not uploaded via django form

8👍

you should use in template where you are uploading form:

    <form class="form-horizontal form_middle" enctype='multipart/form-data' method="POST">
#apply logic for media upload
</form>

2👍

in views.y, the form you are saving should also have request.FILES

studentProfileForm = StudentRegisterForm(request.POST, request.FILES)
    if studentProfileForm.is_valid():
        user = studentProfileForm.save()

-1👍

File upload is a bit weird in model forms in django.
Change your forms.py to –

class APostForm(forms.ModelForm):
    photo=forms.FileField(label='Upload image') # or image field
    class Meta:
        model = Post
        fields = {'title','content'}

form.save() will automatically save the field.

Leave a comment