Recall & Review
beginner
What is a function-based view (FBV) in Django?
A function-based view is a simple Python function that takes a web request and returns a web response. It is straightforward and easy to understand, suitable for simple logic.
Click to reveal answer
beginner
What is a class-based view (CBV) in Django?
A class-based view is a Python class that provides methods to handle HTTP requests. It helps organize code better and supports reuse through inheritance and mixins.Click to reveal answer
intermediate
When should you choose a function-based view over a class-based view?
Choose a function-based view when your view logic is simple and straightforward, like a single action or small page, because it is easier to write and understand.
Click to reveal answer
intermediate
What are the advantages of using class-based views?
Class-based views allow code reuse through inheritance, organize complex logic into methods, and provide built-in generic views for common tasks like displaying lists or forms.
Click to reveal answer
intermediate
How does Django handle HTTP methods differently in FBVs and CBVs?
In FBVs, you check the request method inside the function (like if request.method == 'POST'). In CBVs, you define separate methods like get() and post() for each HTTP method, making code cleaner.
Click to reveal answer
Which Django view type is best for simple, one-action pages?
✗ Incorrect
Function-based views are simpler and better for straightforward tasks.
In class-based views, how do you handle a POST request?
✗ Incorrect
Class-based views handle HTTP methods by defining methods like post() for POST requests.
What is a key benefit of class-based views over function-based views?
✗ Incorrect
Class-based views support inheritance, which helps reuse and organize code.
Which view type requires you to manually check request.method?
✗ Incorrect
In function-based views, you check request.method yourself to handle different HTTP methods.
When might you prefer a class-based view?
✗ Incorrect
Class-based views help organize complex logic and multiple HTTP methods better.
Explain the main differences between function-based and class-based views in Django.
Think about how each handles requests and organizes code.
You got /5 concepts.
Describe scenarios when you would choose a function-based view versus a class-based view.
Consider complexity and code reuse needs.
You got /4 concepts.