tags:

views:

27

answers:

1

How can i get file name from request.FILE in Django?

def upload(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            upload = Upload()
            upload.timestamp = datetime.datetime.now()
            save_instance(form, upload)

I tied use this

  if 'filename'  in request.FILES:
         filename = request.FILES['filename']

but it not work.

I need to get file name in variable

+2  A: 
request.FILES['filename'].name

From the request documentation.

If you don't know the key, you can iterate over the files:

for filename, file in request.FILES.iteritems():
    name = request.FILES[filename].name
mipadi
it gives me : expected an indented block. I confuse :(
Pol
ok! how can i check variable name? but i need print it how can i print what is inside?
Pol