mercredi 24 octobre 2018

Django upload image file through inline formset in testing

temp_file = tempfile.NamedTemporaryFile(dir=os.getcwd(), suffix='.jpeg')
data = {
        'profile-TOTAL_FORMS': '1',
        'profile-INITIAL_FORMS': '1',
        'profile-MIN_NUM_FORMS': '1',
        'profile-MAX_NUM_FORMS': '1',
        'profile-id': self.user.id,
        'profile-profile_picture': test_image.name,
        'profile-first_name': self.user.first_name,
        'profile-last_name': self.user.last_name,
}

resp = self.c.post(reverse('home:user-profile', kwargs={'pk': self.user.id}), data)

i am having trouble with the image uploading through inline formset. The image is not uploading . I think i have to pass the image file through MultiValueDict format i dont know how it can be implemented. plz help me.

Aucun commentaire:

Enregistrer un commentaire