public
Created — forked from vdboor/mixins.py

Django view initialization ordering issues

  • Download Gist
mixins.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class BaseViewMixin(object):
def dispatch(self, request, *args, **kwargs):
# Set earlier to ensure that other class methods which expect
# these values to be present can be called in `init`
self.request = request
self.args = args
self.kwargs = kwargs
 
# Run the complete request, returning a response, but allowing
# `init` to either raise exceptions, or hijack the response if
# necessary.
return self.init() or super(BaseViewMixin, self).dispatch(request, *args, **kwargs)
 
def init(self):
# Hook to override in subclasses
pass

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.