You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this chapter, you use return request and then explain this use by :
You’ll note that we return back a HttpRequest object rather than an arbitrary value or even a None
object. We do this because as Python is a dynamically typed language, we can attach additional
attributes to the HttpRequest
If you don't return it, and call it with check_sprinkles(request) instead of request = 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 ?
The text was updated successfully, but these errors were encountered:
Yes, that's explained in the example that follows:
fromdjango.core.exceptionsimportPermissionDenieddefcheck_sprinkles(request):
ifrequest.user.can_sprinkleorrequest.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=Truereturnrequest# Return a HTTP 403 back to the userraisePermissionDenied
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 ?
The text was updated successfully, but these errors were encountered: