On 26 Mrz., 00:29, Malcolm Tredinnick <[EMAIL PROTECTED]>
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': [{'content': '<omitted>', 'content-type':
> > 'application/pdf', 'filename': 'cheeseShop.pdf'}]}>
>
> > 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---