Skip to content

Instantly share code, notes, and snippets.

@pipermerriam
Forked from vdboor/mixins.py
Created November 7, 2012 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pipermerriam/4032482 to your computer and use it in GitHub Desktop.
Save pipermerriam/4032482 to your computer and use it in GitHub Desktop.
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