Skip to content

Instantly share code, notes, and snippets.

@daltonpinheiro
daltonpinheiro / middleware.py
Created March 18, 2019 13:58 — forked from rbtsolis/middleware.py
Django Access the Request or User Object Inside the Models and Signals
# 1) Create a middlewares/middlewares.py file and copy this:
import threading
class RequestMiddleware:
def __init__(self, get_response, thread_local=threading.local()):
self.get_response = get_response
self.thread_local = thread_local
# One-time configuration and initialization.