Created
June 3, 2019 08:09
-
-
Save gtindo/2d600f5734b0d791a05a548e8350c506 to your computer and use it in GitHub Desktop.
Django midleware base
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from api_v1.models import Notification | |
class NotificationMiddleware: | |
def __init__(self, get_response): | |
self.get_response = get_response | |
# One-time configuration and initialization. | |
def __call__(self, request): | |
# Code to be executed for each request before | |
# the view (and later middleware) are called. | |
notifications = Notification.objects.filter(user=request.user) | |
request.notifications = notifications | |
response = self.get_response(request) | |
# Code to be executed for each request/response after | |
# the view is called. | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment