I'm trying to build a website using Django 1.10.5. At the moment I'm working on a way to edit the database objects in the frontend. My plan was to define a form 'EditForm', where the user enters the ID of the object he wants to edit. When I'm testing only that form on the real site to see if I can submit something, I'm getting the following error: 'is_valid() missing 1 required positional argument: 'self''. I can't find my error in the code so thanks in advance for any help or ideas.
from my views.py:
def mymodel_test(request,):
form = EditForm
if request.method == 'POST':
if form.is_valid():
temp_id = form(request.POST)
return render(request, 'mymodel_test.html', {
"Title": "Test",
"form": form
})
EditForm in the forms.py:
class EditForm(forms.Form):
id = forms.IntegerField(label='Edit object with following ID')
mymodel_test.html:
{% extends "base.html" %}
{% block content %}
<form method="post" action="">
{% csrf_token %}
<table>
{{ form }}
</table>
<input type="submit" value="Edit"/>
</form>
{% endblock %}
Probably you are assigning a class not an instance of a class to the form variable. Try:
form = EditForm()
In this case form variable has the is_valid method, but since there is no instance of the class the self argument is missing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With