B. HttpResponse is not called as a function to create an instance
C. The content attribute cannot be set directly
D. HttpResponse must be imported from django.shortcuts
Solution
Step 1: Check how HttpResponse is assigned
The code assigns HttpResponse class itself to response instead of creating an instance by calling HttpResponse().
Step 2: Understand instance vs class usage
To set content, response must be an instance, so HttpResponse() must be called.
Final Answer:
HttpResponse is not called as a function to create an instance -> Option B
Quick Check:
HttpResponse() creates instance, not HttpResponse alone [OK]
Hint: Always call HttpResponse() to create an instance [OK]
Common Mistakes:
Assigning HttpResponse class instead of instance
Trying to set content on class, not instance
Importing HttpResponse from wrong module
5. You want to return a JSON response with content type set correctly using HttpResponse. Which code snippet correctly sets the content type to application/json?
hard
A. return HttpResponse('{"key": "value"}', content_type='application/json')
B. return HttpResponse('{"key": "value"}', type='application/json')
C. return HttpResponse.json('{"key": "value"}')
D. return HttpResponse('{"key": "value"}', mime='application/json')
Solution
Step 1: Recall how to set content type in HttpResponse
The correct parameter to set content type is content_type.
Step 2: Verify the options
Only return HttpResponse('{"key": "value"}', content_type='application/json') uses content_type='application/json' correctly; others use invalid parameters or methods.
Final Answer:
return HttpResponse('{"key": "value"}', content_type='application/json') -> Option A
Quick Check:
Use content_type='application/json' to set JSON response [OK]
Hint: Use content_type='application/json' to set JSON response [OK]
Common Mistakes:
Using wrong parameter names like type or mime
Trying to call non-existent .json() method
Not setting content type for JSON responses
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.