0

From the Django Documentation

In the beginning there was only the view function contract, Django passed your function an HttpRequest and expected back an HttpResponse. This was the extent of what Django provided. Early on it was recognized that there were common idioms and patterns found in view development. Function-based generic views were introduced to abstract these patterns and ease view development for the common cases. The problem with function-based generic views is that while they covered the simple cases well, there was no way to extend or customize them beyond some configuration options, limiting their usefulness in many real-world applications. Class-based generic views were created with the same objective as function-based generic views, to make view development easier. However, the way the solution is implemented, through the use of mixins, provides a toolkit that results in class-based generic views being more extensible and flexible than their function-based counterparts.strong text

3
  • You don't...... Commented Mar 19, 2022 at 13:46
  • I want to find the best cases using it but I can't. Commented Mar 19, 2022 at 13:48
  • @JoraKaryan: class-based views are usually a good idea when the task you have to implement is a standard one: for example listing items of a single model. Whereas function-based views are often used if the logic is "complicated" and does not fit any of the class-based views: stackoverflow.com/a/56679298/67579 Commented Mar 19, 2022 at 14:00

2 Answers 2

1

Apart from the answers listed above, we can use function based view when there is a single HTTP Method (GET/POST/PATCH etc) against a particular URL. In this case we don't need as_view() to map to correct handler methods as there is only one in this case.

Sign up to request clarification or add additional context in comments.

Comments

1

Class-based views in Django is excellent. They are very abstract and sort of handle many things on their own. They can also be altered to fit what you want to implement, but function-based views are very explicit, and often more straightforward if you're going to implement something different or complicated stuff. This may show you why some people like to use function-based views

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.