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()" />
- Django Class-Based View: Would a lock be reduntant in this example?
- Forms which can apply conditions for individual fields in django
Source:stackexchange.com