8👍
✅
Every field in form are required by default (required=True
). Form submitted without information in required field is not valid. You can add path
field to your form in template and it must be filled or you can make path not required:
class SendFileForm(forms.Form):
path = forms.CharField(required=False)
...
or
<form action={% url "sent" %} method="post" enctype="multipart/form-data">
...
{{ form.songfile }}
{{ form.path }}
...
</form>
👤ndpu
15👍
Note:- This answer is Only to help you in debugging the code.
You can print form errors in your views directly.
class YourFormView(generic.edit.CreateView):
def post(self, request, *args, **kwargs):
form = YourForm(request.POST)
for field in form:
print("Field Error:", field.name, field.errors)
2👍
The problem is that there is no path
input in your template. Your request.POST
contains incomplete data thats why your form is not valid.
This is missing in your template:
{{ form.path }}
0👍
In addition to laxmikant’s answer, one more way to debug is get the errors like below,
class YourFormView(generic.edit.CreateView):
def post(self, request, *args, **kwargs):
form = YourForm(request.POST)
print(form.errors)
Note: This is only debugging technique
- Django – skip first row of array
- How to deploy a WordPress site and Django site on the same domain?
- Where is Pip3 Installing Modules?
- Override Django widgets default templates
- How do I make Django-Piston to include related child objects in the serialized output?
Source:stackexchange.com