-
-
Save pipermerriam/4032482 to your computer and use it in GitHub Desktop.
Django view initialization ordering issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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