I'm too lazy to check, but i'm pretty sure the name of your file input
needs to match the name of the form field. Also, try troubleshooting.
Use print statements in the view to see if the file object is being
posted, etc.

On Dec 21, 11:54 pm, vivek_12315 <vivekchauras...@gmail.com> wrote:
> Awaiting reply!
>
> On Dec 22, 3:36 am, vivek_12315 <vivekchauras...@gmail.com> wrote:
>
>
>
> > I am a beginner in Django programming. I am writing a simple module
> > for file upload looking at link:
>
> >http://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=o...
>
> > I have made a view = upload.py and corresponding html = upload.html.
>
> > Its content are as follows:
>
> > ~~~~~upload.py~~~~~~~
>
> > from django import
> > forms
> > from django.http import HttpResponseRedirect
> > from django.shortcuts import render_to_response
>
> > # Imaginary function to handle an uploaded file.
> > #from somewhere import handle_uploaded_file
> > class UploadFileForm(forms.Form):
> >     title = forms.CharField(max_length=100)
> >     file  = forms.FileField()
>
> > def upload_file(request):
> >     if request.method == 'POST':
> >         form = UploadFileForm(request.POST, request.FILES)
> >         if form.is_valid():
> >             handle_uploaded_file(request.FILES['file'])
> >             html = "<html><body>success in upload </body></html>"
> >             return HttpResponseRedirect(html)
> >     else:
> >         form = UploadFileForm()
> >     return render_to_response('upload.html', {'form': form})
>
> > def handle_uploaded_file(f):
> >     destination = open('/home/bluegene/doom.txt', 'wb+')
> >     for chunk in f.chunks():
> >         destination.write(chunk)
> >     destination.close()
>
> > ~~~~~~~~~~~~end~~~~~~~~~~~~
>
> > ~~~~~upload.html~~~~~~~
> > <html>
> > <body>
> > <div id="indexing">
> > <center>
> > <span id="heading"><h2> ---Upload--- Documents</h2></span>
> > <br><br>
> > <form action="." enctype="multipart/form-data" method="POST">
> >         <input type="file" name="uploaded"/>
> >         <input type="submit" value="upload"/>
> > </form>
> > <br><br>
> > <span id="note">Please enter the /path/name/of/directory containing
> > the documents to be indexed.</span>
> > <br><br>
> > </center>
> > </div>
>
> > </body>
> > </
> > html>
>
> > ~~~~~~~~~~~~end~~~~~~~~~~~~
>
> > When I browse for the file and hit 'upload' button, the shell shows a
> > POST request like:
>
> > [21/Dec/2010 16:31:32] "POST /index/ HTTP/1.1" 200 437
>
> > but I don't get a new file named "doom.txt" which I should.
>
> > Is there something wrong in my code ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to