Hi Jani, form.errors gives error as - <ul class="errorlist"><li>item<ul class="errorlist"><li>This field is required.< /li></ul></li></ul>
can u plz tell me where i did wrong? On Sun, 21 Apr 2019 at 16:43, Jani Tiainen <[email protected]> wrote: > completed is a required field and you're not passing any value with it. If > you print form.errors you would should see that it complains about > "completed" "this field is required" > > Note that providing default value in a model is not same as making field > optional. > > On Fri, Apr 19, 2019 at 2:05 PM Sipum Mishra <[email protected]> wrote: > >> 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 >> <https://groups.google.com/d/msgid/django-users/4ca5e82d-f34b-4ab4-8f82-5be0dcdebecc%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Jani Tiainen > Software wizard > > https://blog.jani.tiainen.cc/ > > Always open for short term jobs or contracts to work with Django. > > -- > 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/CAHn91of6O55rPh6fJFDHQ1Pc2v5Lk%3DT8JtN1wS_4NVuP9vi3MA%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAHn91of6O55rPh6fJFDHQ1Pc2v5Lk%3DT8JtN1wS_4NVuP9vi3MA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAGHZBzxTPyWzT_5GJ3zPsvHmWPHQOka5uM2-yHq9tM4g8urQZg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

