Skip to content Skip to sidebar Skip to footer

Django Create View Image Upload

I'm trying to create a new object in a CreateView via ModelForm. I want the 'player' instance to have a image. But the uploaded image doesn't get stored to the 'player_image'-direc

Solution 1:

There might be something missing like request.FILES in views.py or enctype="multipart/form-data" in the form.

Look here: https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/

or see this : https://godjango.com/35-upload-files/

Solution 2:

Go to your template and add:

<formmethod="post"enctype="multipart/form-data">

Solution 3:

I don't know why it's not working but in my project, which works, I'm getting the image from the post request like so:

profile_form = ProfileForm(data=request.POST)
if profile_form.is_valid():
    if'picture'in request.FILES:
        current_user.image = request.FILES['image']

Post a Comment for "Django Create View Image Upload"