title: How to check if a file is csv or not?
body: <p>I have a django views function that converts csv into another delimiter format. But, I just want to convert csv file and reject other files.</p>
  <pre><code>def index(request):
      csv_form = ''
      if request.method == 'POST':
          csv_form = CsvForm(request.POST, request.FILES)
          if csv_form.is_valid():
              csv_file = TextIOWrapper(request.FILES['csv_file'].file, encoding='ascii', errors='replace')
              #other actions
  </code></pre>
  <p>I cannot use the below code because this works with only binary files, but the csv module wants to have text-mode files instead. Any alternatives to proceed with only csv files.</p>
  <pre><code>if not csv_file.name.endswith('.csv'):
      messages.error(request, 'THIS IS NOT A CSV FILE')
  </code></pre>