Demian
Demian

Reputation: 103

Are class based views widely used by the Django community?

I am new to Django and Python and after reading a lot I decided not to use global functions as views (maybe because I am not used to global functions but mostly because I want a better reuse level and prefer to have smaller code blocks). The problem is that most of the Django apps I have been checking do not use a class based approach.

Is this because I am checking code in the wrong places (I started with the Django tutorial and then on github)?

I'm asking this because in the future I hope to be working with more Django programmers and don't want to adopt a non-standard approach at the beginning.

Upvotes: 9

Views: 3136

Answers (1)

mouad
mouad

Reputation: 70021

One fact is that class based view was added in Django 1.3, so if you're planning to support old Django version than you will have to stick with function view, for example if you want to create a generic app and launch it in GitHub or such for other people to use.

As for when to use class based view over function view i think this will depend on your use case, my advice is that you have to understand the advantage of each way, and IMHO it's pretty normal to have both implementation in a single project.

There was this nice article of Nick Coghlan on response to another great article CBV were a mistake that it worth to check.

Hope this was helpful :)

Upvotes: 11

Related Questions