class bade view

8 views
Skip to first unread message

shahab....@gmail.com

unread,
Feb 11, 2017, 6:05:43 PM2/11/17
to Django users
hello

i have learned some django and but i write my views in method base views.

i dont now how to use class base views and i am not interested to learn class base views
because i think it's redundant .

do i have to learn it ?
i that possible method base views will remove in next version of django?
thanks

ludovic coues

unread,
Feb 12, 2017, 6:31:48 AM2/12/17
to django...@googlegroups.com
We call it function based view. Method are function attached to an object.

As far as I know, there is no plan to remove function based view.



But in my opinion, you should definitely have a look at class based
view. They really shine in common task.

An example, a view to create an object will take something like 10 to
20 lines of code in function based view. You need to treat the case of
showing the form, handling a valid form, handling a form with
validation error.
With class based view, that's 4 lines. Declare a class inheriting from
UpdateView, define the url to redirect to in case of valid form, which
model to update and which field to update.

So sure, they are redundant. But they save a lot of time, make the
code easier to understand and prevent error in commons case.
> --
> 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 django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> 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/8c81adf0-06e3-400c-beb3-07155e26fa25%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages