Recall & Review
beginner
What does the
@require_GET decorator do in Django views?The
@require_GET decorator allows a Django view to accept only HTTP GET requests. If a different request method is used, Django returns a 405 Method Not Allowed response.Click to reveal answer
beginner
How does the
@require_POST decorator affect a Django view?The
@require_POST decorator restricts a Django view to accept only HTTP POST requests. Requests with other methods get a 405 Method Not Allowed response.Click to reveal answer
intermediate
Why use
@require_GET or @require_POST decorators in Django?They help make views safer and clearer by ensuring only the intended HTTP methods are allowed, preventing accidental or malicious requests with wrong methods.
Click to reveal answer
beginner
What HTTP status code does Django return if a request method is not allowed by
@require_GET or @require_POST?Django returns a 405 Method Not Allowed status code when the request method does not match the decorator's requirement.
Click to reveal answer
intermediate
Can you combine
@require_GET and @require_POST on the same Django view?No, combining
@require_GET and @require_POST on the same view doesn't make sense because they restrict to different HTTP methods. Use @require_http_methods if multiple methods are allowed.Click to reveal answer
What happens if a Django view decorated with
@require_GET receives a POST request?✗ Incorrect
The @require_GET decorator only allows GET requests. Other methods like POST get a 405 Method Not Allowed response.
Which decorator restricts a Django view to only accept POST requests?
✗ Incorrect
@require_POST restricts the view to POST requests only.
If you want a Django view to accept both GET and POST requests, which decorator should you use?
✗ Incorrect
@require_http_methods(['GET', 'POST']) allows multiple HTTP methods.
What HTTP status code indicates a method is not allowed on a Django view?
✗ Incorrect
405 means Method Not Allowed, used when the HTTP method is blocked by decorators like @require_GET.
Which of these is a benefit of using
@require_POST on a Django view?✗ Incorrect
Restricting to POST helps prevent unwanted or unsafe requests, improving security.
Explain how
@require_GET and @require_POST decorators control access to Django views.Think about what happens when a request uses the wrong method.
You got /3 concepts.
Describe a situation where you would use
@require_POST in a Django application.Consider when data changes happen in web apps.
You got /3 concepts.