Module Expr Str ImportFrom alias alias Import alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Assign NameStore Call NameLoad For TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr body Assign SubscriptStore NameLoad Index NameLoad Call NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body If BoolOpAnd Call NameLoad NameLoad Str CompareNotEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr body For TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr body If CompareNotEq Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad Return NameLoad decorator_list decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body If Call NameLoad NameLoad NameLoad body Return CompareEq Call NameLoad NameLoad NameLoad orelse If Call NameLoad NameLoad NameLoad body Return CompareEq Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If Call NameLoad NameLoad NameLoad body Return CompareNotEq Call NameLoad NameLoad NameLoad orelse If Call NameLoad NameLoad NameLoad body Return CompareNotEq Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return Call NameLoad NameLoad decorator_list decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Call NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Str NameLoad NameLoad Str NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad NameLoad For NameStore TupleLoad Str Str Str Str Str body Assign NameStore SubscriptLoad Call NameLoad Index NameLoad If CompareIsNot NameLoad NameLoad body Assign SubscriptStore SubscriptLoad NameLoad Index NameLoad Index Call AttributeLoad NameLoad attr Str Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Str NameLoad body Assign SubscriptStore NameLoad Index NameLoad Str If CompareIsNot NameLoad NameLoad body Assign SubscriptStore SubscriptLoad NameLoad Index NameLoad Index Str NameLoad If CompareIsNot NameLoad NameLoad body Assign SubscriptStore SubscriptLoad NameLoad Index NameLoad Index Str NameLoad Assign SubscriptStore SubscriptLoad NameLoad Index NameLoad Index Str Num Assign SubscriptStore SubscriptLoad NameLoad Index NameLoad Index Str Num decorator_list decorator_list
N/A N/A From http://www.davidcramer.net/code/62/set-cookies-without-a-response-in-django.html

Used with permission.  Thank you David Cramer.

To install, add the prehandler to the beginning of your middleware list, and the posthandler to the end.  Then, you can use request.COOKIES.get|set|delete anywhere in the code and they'll be automatically added to the response.
 Cookie SimpleCookie Morsel N/A copy CookiePreHandlerMiddleware N/A object N/A N/A 
    This middleware modifies request.COOKIES and adds a set and delete method.
 
    `set` matches django.http.HttpResponse.set_cookie
    `delete` matches django.http.HttpResponse.delete_cookie
 
    This should be the first middleware you load.
     process_request N/A N/A self request N/A N/A N/A cookies N/A CookieHandler N/A N/A k v N/A N/A N/A request COOKIES iteritems N/A N/A N/A cookies N/A k N/A str v N/A N/A request COOKIES cookies N/A N/A request _orig_cookies N/A N/A copy deepcopy N/A request COOKIES N/A N/A CookiePostHandlerMiddleware N/A object N/A N/A 
    This middleware modifies updates the response will all modified cookies.
 
    This should be the last middleware you load.
     process_response N/A N/A self request response N/A N/A N/A N/A N/A hasattr request _orig_cookies N/A N/A request COOKIES N/A request _orig_cookies N/A N/A N/A k v N/A N/A N/A request COOKIES iteritems N/A N/A N/A N/A N/A N/A request _orig_cookies get k v N/A N/A N/A N/A dict __setitem__ N/A response cookies k v N/A response N/A N/A StringMorsel N/A Morsel N/A __str__ N/A N/A self N/A N/A N/A N/A self value N/A __eq__ N/A N/A self a N/A N/A N/A N/A isinstance a str N/A N/A N/A N/A str self a N/A N/A N/A isinstance a Morsel N/A N/A N/A N/A N/A a output N/A N/A self output N/A False N/A __ne__ N/A N/A self a N/A N/A N/A N/A isinstance a str N/A N/A N/A N/A str self a N/A N/A N/A isinstance a Morsel N/A N/A N/A N/A N/A a output N/A N/A self output N/A True N/A __repr__ N/A N/A self N/A N/A N/A N/A str self N/A N/A CookieHandler N/A SimpleCookie N/A __set N/A N/A self key real_value coded_value N/A N/A N/A Private method for setting a cookie's value N/A M N/A N/A self get key N/A StringMorsel N/A N/A N/A M set key real_value coded_value N/A N/A N/A dict __setitem__ self key M N/A __setitem__ N/A N/A self key value N/A N/A N/A Dictionary style assignment. N/A N/A rval cval N/A N/A self value_encode value N/A N/A N/A self __set key rval cval N/A set N/A N/A self key value max_age expires path domain secure N/A None None / None None N/A N/A N/A self N/A key value N/A var N/A max_age path domain secure expires N/A N/A val N/A N/A locals N/A var N/A N/A val None N/A N/A N/A N/A self N/A key N/A N/A N/A var replace _ - val N/A delete N/A N/A self key path domain N/A / None N/A N/A N/A self N/A key N/A N/A path None N/A N/A N/A N/A self N/A key N/A path path N/A N/A domain None N/A N/A N/A N/A self N/A key N/A domain domain N/A N/A N/A self N/A key N/A expires 0 N/A N/A N/A self N/A key N/A max-age 0 N/A N/A