Skip to content

Instantly share code, notes, and snippets.

View d-rama's full-sized avatar
🏠
Working from home

Dennis Rama d-rama

🏠
Working from home
View GitHub Profile
@rbtsolis
rbtsolis / middleware.py
Created May 3, 2018 02:46
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.