Everything looks right in your code, on a brief glance. In your template, do you have your form prepared for multipart data; Does your form tag look like <form enctype="multipart/form-data" method="post" action="/foo/"> ?
Might be something else, but that is the first thing that jumps out to me. Michael On Mar 10, 6:09 am, Paolo Ferretti <[EMAIL PROTECTED]> wrote: > I've got a problem with file upload in django. I found some generic > documentation like this: > > http://www.djangoproject.com/documentation/model-api/#filefieldhttp://www.djangoproject.com/documentation/faq/#how-do-i-use-image-an... > > Reading that pages, I suppose that the file uploading copy into my > MEDIA_ROOT happens automatically when I save my record. > The problem is that the file name is saved into my database table, but > the file isn't saved into the MEDIA_ROOT directory in the filesystem. > Where am I wrong? Here is the code (I use django SVN version under > Windows XP): > > # models.py > > class Auto(models.Model): > [...others field...] > foto = models.ImageField(upload_to="images/auto/", blank=True, > null=True) > > # forms.py > > class AddImageForm(forms.Form): > immagine = forms.ImageField(label='Immagine:', required=True) > > # views.py > > def addphotoauto(request, id): > if request.method == 'GET': > form = AddImageForm() > return render_to_response('auto/aggiungi_foto.html', {'form': > form}) > if request.method == 'POST': > form = AddImageForm(request.POST, request.FILES) > if form.is_valid(): > try: > a = Auto.objects.get(id__exact = id) > a.foto = form.cleaned_data.get('immagine') > a.save() > # TODO: save file > return HttpResponseRedirect('/') > except Exception, e: > # exception handling > else: > return render_to_response('auto/aggiungi_foto.html', > {'form': form}) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---