Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 21, 2010 22:36:10

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


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=olddocsI 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)
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:

"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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 22, 2010 04:54:53

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


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)
>             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:
>
> "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 22, 2010 17:50:35

Nick S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


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)
> >             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:
>
> > "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 22, 2010 18:18:15

y.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


Nick is right, you need to change your view code to
handle_uploaded_file(request.FILES)
instead of
handle_uploaded_file(request.FILES)

I'm not sure a request object can process a file upload
you may need to use RequestContext in your view definition

On Dec 22, 7:50 pm, Nick Serra <nickse...@gmail.com> wrote:
> 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)
> > >             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:
>
> > > "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 26, 2010 04:29:57

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


If I use print statements in view python files, where can I see the
output ? I am using django dev. server for initial testing of my
website....

On Dec 22, 1:18 pm, yiftah <yifta...@hotmail.com> wrote:
> Nick is right, you need to change your view code to
> handle_uploaded_file(request.FILES)
> instead of
> handle_uploaded_file(request.FILES)
>
> I'm not sure a request object can process a file upload
> you may need to use RequestContext in your view definition
>
> On Dec 22, 7:50 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > 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)
> > > >             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:
>
> > > > "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Dec. 26, 2010 05:44:10

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


If I use print statements in view python files, where can I see the
output ? I am using django dev. server for initial testing of my
website....

On Dec 22, 1:18 pm, yiftah <yifta...@hotmail.com> wrote:
> Nick is right, you need to change your view code to
> handle_uploaded_file(request.FILES)
> instead of
> handle_uploaded_file(request.FILES)
>
> I'm not sure a request object can process a file upload
> you may need to use RequestContext in your view definition
>
> On Dec 22, 7:50 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > 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)
> > > >             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:
>
> > > > "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 Dec. 26, 2010 05:45:27

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


Never mind ,,,, I am able to see print statements in dev server shell
output ....

There is some problem with my upload.html as the 'form' variable
returned by python script is not used at html end...

This e.g. helped me much :http://www.zoia.org/blog/2007/07/29/django-file-upload/On Dec 25, 11:29 pm, vivek_12315 <vivekchauras...@gmail.com> wrote:
> If I use print statements in view python files, where can I see the
> output ? I am using django dev. server for initial testing of my
> website....
>
> On Dec 22, 1:18 pm, yiftah <yifta...@hotmail.com> wrote:
>
> > Nick is right, you need to change your view code to
> > handle_uploaded_file(request.FILES)
> > instead of
> > handle_uploaded_file(request.FILES)
>
> > I'm not sure a request object can process a file upload
> > you may need to use RequestContext in your view definition
>
> > On Dec 22, 7:50 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > > 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)
> > > > >             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:
>
> > > > > "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 Dec. 26, 2010 06:31:33

v.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with simple file upload.


Never mind ,,,, I am able to see print statements in dev server shell
output ....

There is some problem with my upload.html as the 'form' variable
returned by python script is not used at html end...

This e.g. helped me much :http://www.zoia.org/blog/2007/07/29/django-file-upload/On Dec 25, 11:29 pm, vivek_12315 <vivekchauras...@gmail.com> wrote:
> If I use print statements in view python files, where can I see the
> output ? I am using django dev. server for initial testing of my
> website....
>
> On Dec 22, 1:18 pm, yiftah <yifta...@hotmail.com> wrote:
>
> > Nick is right, you need to change your view code to
> > handle_uploaded_file(request.FILES)
> > instead of
> > handle_uploaded_file(request.FILES)
>
> > I'm not sure a request object can process a file upload
> > you may need to use RequestContext in your view definition
>
> > On Dec 22, 7:50 pm, Nick Serra <nickse...@gmail.com> wrote:
>
> > > 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)
> > > > >             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:
>
> > > > > "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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support