[Django]-Django class based views – request, args and kwargs objects

5👍

Although some CBV methods (like dispatch()) have the arguments passed to them directly, others do not. And, of course, you might want to define your own methods that have access to these values without having to pass them around.

Part of the point of CBVs is that you don’t have to think as much about the flow of control (who is calling what); instead, you can just override small bits of functionality (e.g. get_context_data()). So it’s more natural to think of data attached to the object rather than arguments that are passed around from method to method.

Why not get rid of the arguments entirely? Probably because it’s a better match to the legacy of function-based views. For example, many FBVs will have a CBV equivalent that uses the exact same code in the get() method.

Leave a comment