File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -195,4 +195,20 @@ Instead of::
195195The `.save()` should return a Model Object
196196
197197
198+ Code defensively in middleware and context processors.
199+ -----------------------------------------------------------
200+ Your middleware and context processors are going to be run for **all** requests.
201+ Have you handled all cases?
202+ 
203+     def process_request(request):
204+         if user.is_authenticated():
205+             profile = request.user.get_profile()#Hah, I create profiles during
206+                                         #registration so this is safe.
207+             ...
208+             
209+ Or it is? What about users created via `manage.py createsuperuser`, with the
210+ above middleware, the default user can not even access the admi site.
198211
212+ Hence handle all scenarios in middleware and context processors. This is one place
213+ where `try: .. except: ..` (bare except) block are acceptable. You do not wnat one
214+ middleare  bringing down entire site.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments