[Fixed]-Uploading a file using django

0👍

I have missed enctype=”multipart/form-data” command in my form tag in my HTML file. So, my form in the HTML file must be such as bellow:

<form  class="myclass" action="submit" enctype="multipart/form-data" method="post">
    {% csrf_token %}

    <p>
                {{ form.docfile.errors }}
                {{ form.docfile }}
</p>
            <input type="submit" value="upload" id="button" class="top-menu" onclick="pythonhandler()" />

1👍

in your view function

def pythonhandler(request):
data = DocumentForm(request.POST, request.FILES)

and in your html file

<form  class="myclass" action="submit" enctype="multipart/form-data" method="post">
    {% csrf_token %}

    <p>
                {{ form.docfile.errors }}
                {{ form.docfile }}
</p>
            <input type="submit" value="upload" id="button" class="top-menu" onclick="pythonhandler()" />

Leave a comment