Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 March 26, 2008 00:19:29

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

File upload doesn't work


Hi Djangonauts,

i've a problem here driving me nuts - obviously I don't get it how to
do a simple file upload:

With a form like this:

<form action="." method="post" id="form" enctype="multipart/form-
data">
<input type='file' name='foo'/>
<input type='submit' value='submit'/>
</form>

and a view function like this:

def test(request):
if request.method=='GET':
return render_to_response('test.html')
else:
assert False, request.FILES

request.FILES has the following value (f. ex. a pdf):

<MultiValueDict: {'foo': }>

As far as I understand, this means the file wasn't uploaded
('content': '<omitted>').

I'm running the latest checkout and have set the MEDIA_ROOT and
MEDIA_URL settings.

Anyone an idea why this doesn't work?
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 March 26, 2008 00:32:37

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

File upload doesn't work


On Tue, 2008-03-25 at 16:19 -0700, Carl wrote:
> Hi Djangonauts,
>
> i've a problem here driving me nuts - obviously I don't get it how to
> do a simple file upload:
>
> With a form like this:
>
> <form action="." method="post" id="form" enctype="multipart/form-
> data">
> <input type='file' name='foo'/>
> <input type='submit' value='submit'/>
> </form>
>
> and a view function like this:
>
> def test(request):
> if request.method=='GET':
> return render_to_response('test.html')
> else:
> assert False, request.FILES
>
> request.FILES has the following value (f. ex. a pdf):
>
> <MultiValueDict: {'foo': }>
>
> As far as I understand, this means the file wasn't uploaded
> ('content': '<omitted>').
>
> I'm running the latest checkout and have set the MEDIA_ROOT and
> MEDIA_URL settings.
>
> Anyone an idea why this doesn't work?

The reason Django displays <omitted> there is because most files are not
just a few bytes long. If we displayed the tens, hundreds or thousands
of kilobytes of data in the file content, it would completely swamp the
printed output. So we omit the content from the printed output.

If you actually look inside the dictionary, you'll see that the
"content" attribute has plenty of data there.

Regards,
Malcolm

--
On the other hand, you have different fingers.http://www.pointy-stick.com/blog/--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#3 March 26, 2008 01:51:42

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

File upload doesn't work


On 26 Mrz., 00:29, Malcolm Tredinnick <>
wrote:
> On Tue, 2008-03-25 at 16:19 -0700, Carl wrote:
> > Hi Djangonauts,
>
> > i've a problem here driving me nuts - obviously I don't get it how to
> > do a simple file upload:
>
> > With a form like this:
>
> > <form action="." method="post" id="form" enctype="multipart/form-
> > data">
> >       <input type='file' name='foo'/>
> >       <input type='submit' value='submit'/>
> > </form>
>
> > and a view function like this:
>
> > def test(request):
> >   if request.method=='GET':
> >     return render_to_response('test.html')
> >   else:
> >     assert False, request.FILES
>
> > request.FILES has the following value (f. ex. a pdf):
>
> > <MultiValueDict: {'foo': }>
>
> > As far as I understand, this means the file wasn't uploaded
> > ('content': '<omitted>').
>
> > I'm running the latest checkout and have set the MEDIA_ROOT and
> > MEDIA_URL settings.
>
> > Anyone an idea why this doesn't work?
>
> The reason Django displays <omitted> there is because most files are not
> just a few bytes long. If we displayed the tens, hundreds or thousands
> of kilobytes of data in the file content, it would completely swamp the
> printed output. So we omit the content from the printed output.
>
> If you actually look inside the dictionary, you'll see that the
> "content" attribute has plenty of data there.
>
> Regards,
> Malcolm
>
> --
> On the other hand, you have different
> fingers.http://www.pointy-stick.com/blog/Hi Malcom,

thanks for your super-fast help!
So I was expecting the mistake at the wrong place. Still nothing gets
written on my disk, only the database gets updated.
My view now looks like this:

def test(request):
if request.method=='GET':
return render_to_response('test.html')
else:
testForm = TestForm(request.POST, request.FILES)
if testForm.is_valid():
test=Test(**testForm.cleaned_data)
test.save()
return HttpResponse('saved!')
else:
(...)

When I try to inspect the test object just after it got saved, I can't
get his URL via get_file_url(), it just says it has no finder
attribute.

To make this complete here's the model:

class Test(models.Model):
file = models.FileField(upload_to='temp', null=False, blank=False)

and that are the settings relevant to upload:

MEDIA_ROOT 'C:/DATA/Projekte/totale/nextdraft/uploaded_Files/'
MEDIA_URL 'http://localhost:8000/firstdraft/files/'

Anyone an idea where I mess up?

Thanks in advance,

Carl


--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#4 March 26, 2008 10:51:25

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

File upload doesn't work


On 26 Mrz., 01:51, Carl <> wrote:
> On 26 Mrz., 00:29, Malcolm Tredinnick <>
> wrote:
>
>
>
> > On Tue, 2008-03-25 at 16:19 -0700, Carl wrote:
> > > Hi Djangonauts,
>
> > > i've a problem here driving me nuts - obviously I don't get it how to
> > > do a simple file upload:
>
> > > With a form like this:
>
> > > <form action="." method="post" id="form" enctype="multipart/form-
> > > data">
> > >       <input type='file' name='foo'/>
> > >       <input type='submit' value='submit'/>
> > > </form>
>
> > > and a view function like this:
>
> > > def test(request):
> > >   if request.method=='GET':
> > >     return render_to_response('test.html')
> > >   else:
> > >     assert False, request.FILES
>
> > > request.FILES has the following value (f. ex. a pdf):
>
> > > <MultiValueDict: {'foo': }>
>
> > > As far as I understand, this means the file wasn't uploaded
> > > ('content': '<omitted>').
>
> > > I'm running the latest checkout and have set the MEDIA_ROOT and
> > > MEDIA_URL settings.
>
> > > Anyone an idea why this doesn't work?
>
> > The reason Django displays <omitted> there is because most files are not
> > just a few bytes long. If we displayed the tens, hundreds or thousands
> > of kilobytes of data in the file content, it would completely swamp the
> > printed output. So we omit the content from the printed output.
>
> > If you actually look inside the dictionary, you'll see that the
> > "content" attribute has plenty of data there.
>
> > Regards,
> > Malcolm
>
> > --
> > On the other hand, you have different
> > fingers.http://www.pointy-stick.com/blog/>
> Hi Malcom,
>
> thanks for your super-fast help!
> So I was expecting the mistake at the wrong place. Still nothing gets
> written on my disk, only the database gets updated.
> My view now looks like this:
>
> def test(request):
>   if request.method=='GET':
>     return render_to_response('test.html')
>   else:
>     testForm = TestForm(request.POST, request.FILES)
>     if testForm.is_valid():
>       test=Test(**testForm.cleaned_data)
>       test.save()
>       return HttpResponse('saved!')
>     else:
>       (...)
>
> When I try to inspect the test object just after it got saved, I can't
> get his URL via get_file_url(), it just says it has no finder
> attribute.
>
> To make this complete here's the model:
>
> class Test(models.Model):
>     file = models.FileField(upload_to='temp', null=False, blank=False)
>
> and that are the settings relevant to upload:
>
> MEDIA_ROOT 'C:/DATA/Projekte/totale/nextdraft/uploaded_Files/'
> MEDIA_URL 'http://localhost:8000/firstdraft/files/'
>
> Anyone an idea where I mess up?
>
> Thanks in advance,
>
> Carl

Hi Djangonauts!

I'm still stuck here - any tip will be appreciated!

Thanks a lot,

Carl
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#5 March 26, 2008 23:35:01

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

File upload doesn't work


On Tue, Mar 25, 2008 at 8:51 PM, Carl <> wrote:

> On 26 Mrz., 00:29, Malcolm Tredinnick <>
> wrote:
> > On Tue, 2008-03-25 at 16:19 -0700, Carl wrote:
> > > Hi Djangonauts,
> >
> > > i've a problem here driving me nuts - obviously I don't get it how to
> > > do a simple file upload:
> >
> > > With a form like this:
> >
> > > <form action="." method="post" id="form" enctype="multipart/form-
> > > data">
> > > <input type='file' name='foo'/>
> > > <input type='submit' value='submit'/>
> > > </form>
> >
> > > and a view function like this:
> >
> > > def test(request):
> > > if request.method=='GET':
> > > return render_to_response('test.html')
> > > else:
> > > assert False, request.FILES
> >
> > > request.FILES has the following value (f. ex. a pdf):
> >
> > > <MultiValueDict: {'foo': }>
> >
> > > As far as I understand, this means the file wasn't uploaded
> > > ('content': '<omitted>').
> >
> > > I'm running the latest checkout and have set the MEDIA_ROOT and
> > > MEDIA_URL settings.
> >
> > > Anyone an idea why this doesn't work?
> >
> > The reason Django displays <omitted> there is because most files are not
> > just a few bytes long. If we displayed the tens, hundreds or thousands
> > of kilobytes of data in the file content, it would completely swamp the
> > printed output. So we omit the content from the printed output.
> >
> > If you actually look inside the dictionary, you'll see that the
> > "content" attribute has plenty of data there.
> >
> > Regards,
> > Malcolm
> >
> > --
> > On the other hand, you have different fingers.http://www.pointy-> stick.com/blog/
>
> Hi Malcom,
>
> thanks for your super-fast help!
> So I was expecting the mistake at the wrong place. Still nothing gets
> written on my disk, only the database gets updated.
> My view now looks like this:
>
> def test(request):
> if request.method=='GET':
> return render_to_response('test.html')
> else:
> testForm = TestForm(request.POST, request.FILES)
> if testForm.is_valid():
> test=Test(**testForm.cleaned_data)
> test.save()
> return HttpResponse('saved!')
> else:
> (...)
>
> When I try to inspect the test object just after it got saved, I can't
> get his URL via get_file_url(), it just says it has no finder
> attribute.
>
> To make this complete here's the model:
>
> class Test(models.Model):
> file = models.FileField(upload_to='temp', null=False, blank=False)
>
> and that are the settings relevant to upload:
>
> MEDIA_ROOT 'C:/DATA/Projekte/totale/nextdraft/uploaded_Files/'
> MEDIA_URL 'http://localhost:8000/firstdraft/files/'
>
> Anyone an idea where I mess up?
>
> Thanks in advance,
>

What's TestForm? If it's a ModelForm for your Test model then you should be
instantiating and saving a Test model instance like so:

testForm = TestForm(request.POST, request.FILES)
if testForm.is_valid():
test=testForm.save()
return HttpResponse('saved! %s' % (test.get_file_filename()))

Karen

--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

Board footer

Moderator control

Enjoy the 16th of December
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