Recall & Review
beginner
What is a function-based view (FBV) in Django?
A function-based view is a Python function that takes a web request and returns a web response. It handles the logic for a specific URL in a simple, direct way.
Click to reveal answer
beginner
What parameter does a function-based view always receive?
A function-based view always receives a
request object as its first parameter, which contains details about the web request.Click to reveal answer
beginner
How do you return a simple HTML response from a function-based view?
Use
HttpResponse from django.http to return HTML content. For example: <br>return HttpResponse('<h1>Hello</h1>')Click to reveal answer
beginner
How do you connect a function-based view to a URL in Django?
In the <code>urls.py</code> file, import the view function and add a path with the URL pattern and the view function name. For example: <br><code>path('home/', views.home_view)</code>Click to reveal answer
beginner
Why might you choose a function-based view over a class-based view?
Function-based views are simple and easy to understand for small or straightforward tasks. They are good for beginners and quick setups without extra structure.
Click to reveal answer
What does a function-based view in Django always take as its first argument?
✗ Incorrect
A function-based view always takes the request object as its first argument.
Which Django module provides the HttpResponse class used in function-based views?
✗ Incorrect
HttpResponse is imported from django.http to send back responses.
How do you link a function-based view to a URL pattern?
✗ Incorrect
You import the view in urls.py and add it to urlpatterns with a path.
What is the typical return type of a function-based view?
✗ Incorrect
Function-based views return an HttpResponse object that contains the response data.
Which of these is a reason to use function-based views?
✗ Incorrect
Function-based views are simpler and easier to understand for beginners and small tasks.
Explain how a function-based view works in Django from receiving a request to sending a response.
Think about the steps from when a user visits a URL to what the server sends back.
You got /4 concepts.
Describe how you would set up a new function-based view and connect it to a URL in a Django project.
Consider both the view code and the URL configuration.
You got /4 concepts.