Skip to content

Commit

Permalink
Added pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
shabda committed Sep 6, 2009
1 parent 9a5ec45 commit 757968e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,20 @@ Instead of::
The `.save()` should return a Model Object


Code defensively in middleware and context processors.
-----------------------------------------------------------
Your middleware and context processors are going to be run for **all** requests.
Have you handled all cases?

def process_request(request):
if user.is_authenticated():
profile = request.user.get_profile()#Hah, I create profiles during
#registration so this is safe.
...

Or it is? What about users created via `manage.py createsuperuser`, with the
above middleware, the default user can not even access the admi site.

Hence handle all scenarios in middleware and context processors. This is one place
where `try: .. except: ..` (bare except) block are acceptable. You do not wnat one
middleare bringing down entire site.

0 comments on commit 757968e

Please sign in to comment.