title: How can I get file name from request.FILE in Django?
body: <p>I tried this code for saving images. It saves the image at the given path, but does not get the file name. How can I get it?</p>
  
  <pre><code>@csrf_exempt
  def upload_file(request):
      if request.method == 'POST':
  
          form = UploadFileForm(request.POST, request.FILES)
  
      if 'filename'  in request.FILES:
          filename = request.FILES['filename'].name
          if form.is_valid():
              handle_uploaded_file(request.FILES['file'])
              return HttpResponseRedirect('/user_profileform/')
      else:
  
          form = UploadFileForm()
      return render_to_response('user_profile.html', {'form': form })
  
  def handle_uploaded_file(f):
  
      destination = open('media/filename', 'wb+')
      for chunk in f.chunks(): 
          destination.write(chunk)
      destination.close()
  </code></pre>