I am trying to import csv file i am able to import without any problem but the present functionality accepts all file types, i want the functionality to accept only csv file. below is the view.py and template file.

myapp/views.py

```
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            importing_file(request.FILES['docfile'])

```

myapp/templates/myapp/index.html

```
 <form action="{% url 'ml:list' %}" method="post" enctype="multipart/form-data">
            {% csrf_token %}
            <p>{{ form.non_field_errors }}</p>

            <p>{{ form.docfile.label_tag }} {{ form.docfile.help_text }}</p>

            <p>
                {{ form.docfile.errors }}
                {{ form.docfile }}
            </p>

            <p><input type="submit" value="Upload"/></p>
        </form>

```

> 
> EDIT
> 
> 
> I could find a workaround by adding validate\_file\_extension as per the
>  [django documentation](https://docs.djangoproject.com/en/1.10/ref/forms/validation/#cleaning-a-specific-field-attribute)
> 
> 
> myapp/forms.py
> 
> 
> 

```
def validate_file_extension(value):
        if not value.name.endswith('.csv'):
            raise forms.ValidationError("Only CSV file is accepted")
class DocumentForm(forms.Form): 
    docfile = forms.FileField(label='Select a file',validators=[validate_file_extension])

```