This is bad advice. You should almost never need to override the get or post
methods on a class based view; there are always more specific methods to use.
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group
Is just what i pictured. But when form_invalid is called?
Il giorno lunedì 30 gennaio 2017 02:35:54 UTC+1, Melvyn Sopacua ha scritto:
>
> On Sunday 29 January 2017 04:10:20 Roberto Russi wrote:
>
> > I need get data from a form when submit is clicked even if data are
>
>
t; >> https://ccbv.co.uk is your friend with class based views.
>>> >>
>>> >> I'd override post(self, request, *args, **kwargs), in request.POST,
>>> >> you'll have your form's data (before it's validated).
>>> >>
>>>
t, *args, **kwargs), in request.POST,
>> >> you'll have your form's data (before it's validated).
>> >>
>> >> HTH,
>> >> Norberto
>> >>
>> >> 2017-01-29 9:10 GMT-03:00 Roberto Russi <robrus...@gmail.com>:
>> >&
On Sunday 29 January 2017 04:10:20 Roberto Russi wrote:
> I need get data from a form when submit is clicked even if data are
> invalid, inconplete or empty.
> I try to override form_invalid in CreateView but it is never called
> and form_valid, obviously, only if data are
t; >> HTH,
> >> Norberto
> >>
> >> 2017-01-29 9:10 GMT-03:00 Roberto Russi <robrus...@gmail.com>:
> >>>
> >>> I need get data from a form when submit is clicked even if data are
> invalid, inconplete or empty.
> &
gt;> have your form's data (before it's validated).
>>
>> HTH,
>> Norberto
>>
>> 2017-01-29 9:10 GMT-03:00 Roberto Russi <robrus...@gmail.com>:
>>>
>>> I need get data from a form when submit is clicked even if data are
>>> invalid, inconplete
a are
>> invalid, inconplete or empty.
>> I try to override form_invalid in CreateView but it is never called and
>> form_valid, obviously, only if data are valid.
>> Why form_invalid is never called?
>>
>> I have this test project with django 1.10.5
form when submit is clicked even if data are
> invalid, inconplete or empty.
> I try to override form_invalid in CreateView but it is never called and
> form_valid, obviously, only if data are valid.
> Why form_invalid is never called?
>
> I have this test project with d
I need get data from a form when submit is clicked even if data are
invalid, inconplete or empty.
I try to override form_invalid in CreateView but it is never called and
form_valid, obviously, only if data are valid.
Why form_invalid is never called?
I have this test project with django 1.10.5
Fixed. Was missing:
self.form = self.get_form(self.form_class)
self.object_list = self.get_queryset()
from def form_invalid(self, form):
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiv
Doh, fixed.
Fix below for anyone else with the same problem:
def post(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form, *args, **kwargs)
def form_invalid(self, form, *args, **kwargs):
messages.error
']).pk
data.save()
messages.success(self.request, '{0} added.'.format(self.model.__name__))
if self.request.is_ajax():
return JsonResponse({'reset': True})
return super(ShowForumPostsView, self).form_valid(form)
def form_invalid(self, form):
messages.error(self.request, '{0} could not be
saved
Got this working. See below:
class CreateComment(MultipleObjectMixin, FormView):
template_name = 'comment/comment_list.html'
form_class = CommentForm
model = Comment
paginate_by = 5
def post(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return HttpResponseForbidden()
This is what I am working from
btw:
https://docs.djangoproject.com/en/1.8/topics/class-based-views/mixins/#an-alternative-better-solution
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails
Following a form_invalid I need to redirect to the CreateComment view below
with the errors shown in the form. Is this possible please? Highlighted is
where I need help.
Thank you for any assistance.
class Comments(View):
def get(self, request, *args, **kwargs):
view = CreateComment.as_view
16 matches
Mail list logo