title: How to get the extension of a file in Django?
body: <p>I'm building a web app in Django.
  I have a form that sends a file to views.py.</p>
  
  <p>Views:</p>
  
  <pre><code>@login_required(login_url=login_url)
  def addCancion(request):
      if request.method == 'POST':
          form2 = UploadSong(request.POST, request.FILES)
          if form2.is_valid():
              if(handle_uploaded_song(request.FILES['file'])):
                  path = '%s' % (request.FILES['file'])
                  ruta =  "http://domain.com/static/canciones/%s" % path
                  usuario = Usuario.objects.get(pk=request.session['persona'])
                  song = Cancion(autor=usuario, cancion=ruta)
                  song.save()
                  return HttpResponse(ruta)
              else:
                  return HttpResponse("-3")
          else:
              return HttpResponse("-2")
      else:
          return HttpResponse("-1")   
  </code></pre>
  
  <p>I'm trying to upload only the MP3 files, but I don't know how to make this filter.
  I tried a class named "ContentTypeRestrictedFileField(FileField):" and doesn't work.</p>
  
  <p>How can I get the file type in views.py?</p>
  
  <p>Thanks!</p>