Closed briceparent closed 7 years ago
Yes, that's explained in the example that follows:
from django.core.exceptions import PermissionDenied
def check_sprinkles(request):
if request.user.can_sprinkle or request.user.is_staff:
# By adding this value here it means our display templates
# can be more generic. We don't need to have
# {% if request.user.can_sprinkle or request.user.is_staff %}
# instead just using
# {% if request.can_sprinkle %}
request.can_sprinkle = True
return request
# Return a HTTP 403 back to the user
raise PermissionDenied
In this chapter, you use
return request
and then explain this use by :If you don't return it, and call it with
check_sprinkles(request)
instead ofrequest = check_sprinkles(request)
, you'll have the same effect, as this object is mutable (correct me if I'm wrong), so there should be no reason to make a new assignment and this would lead to thinking that we are able to call the function without modifying the object just by removing the assignment.Is there a reason to make the assignment like you did ?