Create a gist now

Instantly share code, notes, and snippets.

Django view initialization ordering issues
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment