Hi All,

I am always getting - form.is_valid returning False. kindly check where I 
am doing wrong.
please find below code. 


views.py
-----------
def home(request):

if request.method == 'POST':
form = ListForm(request.POST or None)
print(form.is_valid(), "-->",request.POST['Item'])
print(form.errors)
print(form)
if form.is_valid():
form.save()
all_items = List.objects.all
messages.success(request, ('Item has been Added to the List!'))
return render(request,'home.html', {'all_items' : all_items})
else:
print("deba-->",request.POST)
return HttpResponse("Form is invalid!")
else:
all_items = List.objects.all
return render(request,'home.html', {'all_items' : all_items})

-------------
form.py
-------------

class ListForm(forms.ModelForm):
class Meta:
model = List
fields = ["item", "completed"]


--------------------
model.py
---------------------

class List(models.Model):
item = models.CharField(max_length=200)
completed = models.BooleanField(default=False)


def __str__(self):
return self.item + '|' + str(self.completed)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4ca5e82d-f34b-4ab4-8f82-5be0dcdebecc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to