How many developers have moved to class-based views?

114 views
Skip to first unread message

Kevin

unread,
Nov 11, 2012, 5:57:16 PM11/11/12
to django...@googlegroups.com
Hello!

  I am curious of how many existing Django developers have moved over to class-based views or are still using the function-based ones.  I tend to use a mix depending on what I am trying to do.  I try to stick with class-based views, but fallback to function-based ones for process-based views, views which don't return a template but redirect after processing some end-user action.

  At first class-based views were a little confusing and the Django docs didn't really clarify how they work as well under the hood and the best practices on subclassing them.  It took me a little while to properly understand how they worked and what functions to override to do specific tasks.  This mainly involved reading the source code to see how everything worked.

Best Regards,
  Kevin Veroneau
  Python Diary

Lachlan Musicman

unread,
Nov 11, 2012, 6:18:55 PM11/11/12
to django...@googlegroups.com
I'm about to start transferring a few function based views, but like
you am using a mix as needed as it stands.

Re documentation, the docs on the dev stream have significantly more
useful and comprehensive info for class based views.

I think that there will always be a use for function based views (for
instance I'm pushing out a lot of stats on one page, and they don't
compute themselves) but from what I can see, most model based views
should move to the cbv

cheers
L.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/-b1KxU29PYwJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.



--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

Arnold Krille

unread,
Nov 11, 2012, 6:45:17 PM11/11/12
to django...@googlegroups.com
On Sun, 11 Nov 2012 09:57:16 -0800 (PST) Kevin <kver...@gmail.com>
wrote:
> Hello!
>
> I am curious of how many existing Django developers have moved over
> to class-based views or are still using the function-based ones. I
> tend to use a mix depending on what I am trying to do. I try to
> stick with class-based views, but fallback to function-based ones for
> process-based views, views which don't return a template but redirect
> after processing some end-user action.

Docs on CBV in django1.4 are a bit sparse to say the least.

And we started the project before there where CBV.

But we are using CBV for some stuff already, deriving a
JqtableAjaxView from the documentations AjaxView has saved us quite
some code. And simplified testing.
there are other occasions where CBV would result in more code, so we
don't use it there...

One of our greatest problems is that you can't use permission
decorators as easily as with function-views. But on one hand I just
learned about the Mixins of django-braces. And on the other hand most
of our views need object-based permissions with a much more
sophisticated permission model than just users and groups. So we are
doing a lot ourselves and only provide an auth-backend to get our
permissions into the django-mechanisms where its applicable.
And for example its far better to return an empty dataset via an
ajax-call than a 404 or a login-page. So we actually filter the
datasets on what the user is allowed to view and not disturb him with
ugly error-messages...

Have fun,

Arnold
signature.asc

Lee Hinde

unread,
Nov 11, 2012, 6:53:47 PM11/11/12
to django...@googlegroups.com
The dev docs are much more informative.


On Sun, Nov 11, 2012 at 10:45 AM, Arnold Krille <arn...@arnoldarts.de> wrote:

Docs on CBV in django1.4 are a bit sparse to say the least.
<snip /> 

Have fun,

Arnold

Kevin

unread,
Nov 11, 2012, 7:05:53 PM11/11/12
to django...@googlegroups.com
Wow, the dev docs are much more informative and actually explains the best way to alter a form before saving it.  I was using a different method, but the method mentioned in the dev docs are much more cleaner than what I was doing.  Many thanks for this.

Kurtis Mullins

unread,
Nov 12, 2012, 4:16:23 AM11/12/12
to django...@googlegroups.com
I use them!


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/jZ8_sGjQpkoJ.

Tom Christie

unread,
Nov 12, 2012, 10:02:58 AM11/12/12
to django...@googlegroups.com
If you're working with the generic CBVs, I would strongly recommend taking a look at the documentation provided by the Classy CBV project - http://ccbv.co.uk/.  Because of the way it's auto-generated it allows you to see at a glance exactly what set of methods and attributes are implemented by an given class or mixin, and makes it frictionless to skip between the documentation and the source implementation.  It makes it much easier to get an idea of how everything fits together.

  - Tom

Lachlan Musicman

unread,
Nov 12, 2012, 10:13:01 AM11/12/12
to django...@googlegroups.com
On Monday, November 12, 2012, Tom Christie wrote:
If you're working with the generic CBVs, I would strongly recommend taking a look at the documentation provided by the Classy CBV project - http://ccbv.co.uk/.  Because of the way it's auto-generated it allows you to see at a glance exactly what set of methods and attributes are implemented by an given class or mixin, and makes it frictionless to skip between the documentation and the source implementation.  It makes it much easier to get an idea of how everything fits together.

Ooooh. That's nice. Really nice. 

Big high five to CCBV! 

John DeRosa

unread,
Nov 12, 2012, 4:07:10 PM11/12/12
to django...@googlegroups.com
On Nov 11, 2012, at 9:57 AM, Kevin <kver...@gmail.com> wrote:

> Hello!
>
> I am curious of how many existing Django developers have moved over to class-based views or are still using the function-based ones. I tend to use a mix depending on what I am trying to do. I try to stick with

I use only function-based views. I've yet to read a compelling argument for switching.

Kurtis Mullins

unread,
Nov 12, 2012, 4:24:51 PM11/12/12
to django...@googlegroups.com
John,

My argument (or reason for switching) is it's DRY. Saves a lot of time and repetition in the long run ... at least in my experience. On the other hand, there are still perfectly good purposes for "function based views".


--
You received this message because you are subscribed to the Google Groups "Django users" group.

Lachlan Musicman

unread,
Nov 12, 2012, 7:19:30 PM11/12/12
to django...@googlegroups.com
On Tue, Nov 13, 2012 at 4:07 AM, John DeRosa <jo...@ipstreet.com> wrote:
>
> I use only function-based views. I've yet to read a compelling argument for switching.

I think the best argument goes something like:

- if you have previously developed sites that are now stable or only
require minor changes, and wont have any further or much development
there's no need to change
- if you have previously developed sites that are expecting to
grow/change (and have the budget :) ) then you would probably change
- if you are developing a new site, then use CBV

Just like a stable OS, there's no need to update every 6 months just
because you can, unless you enjoy the work it takes.

Cheers
L.

Dan Gentry

unread,
Nov 12, 2012, 7:27:14 PM11/12/12
to django...@googlegroups.com
It took me a few months to warm up to using class based views, and it was the pending decommissioning of the generic function based views that first caused me to take a look.  Now, I have converted all but the most complicated views to the class format (why change what works?).  Any new work I do is in CBV unless there is a compelling reason not to.

I agree with the remark from Kurtis that DRY is a great motivator to use CBVs.  Inspired by braces, I have begun to write my own mixins to minimize code copying.

Kevin

unread,
Nov 12, 2012, 9:00:20 PM11/12/12
to django...@googlegroups.com
That Classy CCBV.CO.OK website is interesting, but I seem to prefer the generated epydoc, it's tree navigation is easy to navigate and it's all auto-generated.  CCBV may also be auto-generated, haven't looked at their github source.

Here's how to generate it locally on your own machine:

epydoc <PATH_TO_DJANGO_ROOT>/views/generic

This will create a local directory called "html", where you can open index.html in your favorite browser.  I am attaching a copy of my generated version for those who may not have epydoc installed(although it's easy to install via PIP).
cbv-epydoc.zip
Reply all
Reply to author
Forward
0 new messages