What is the advantage of Class-Based views?

You can subclass a class and refine methods like get_context_data for specific cases, and leave the rest as-is. You can’t do that with functions.

For instance, you might need to create a new view that does everything a previous one does, but you need to include extra variable in the context. Subclass the original view and override the get_context_data method.

Also, separating the steps needed to render the template into separate methods promotes clearer code – the less done in a method, the easier it is to understand. With regular view functions, it’s all dumped into the one processing unit.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)