Skip to content

Instantly share code, notes, and snippets.

@benbacardi
Last active April 10, 2017 13:10
Show Gist options
  • Save benbacardi/852e4bd9070c7a014e459a7a395f8c4f to your computer and use it in GitHub Desktop.
Save benbacardi/852e4bd9070c7a014e459a7a395f8c4f to your computer and use it in GitHub Desktop.
Django CBV Notes

Stuff I always forget about CBVs

  • self.request is the way to get the request object
  • self.args and self.kwargs are the URL parameters from urls.py (they are also passed to almost every method, but they're not always, and some methods take an args and kwargs that aren't the ones from the URL, so... just use self. everywhere!)
  • dispatch is called before get or post so is a useful place to setup stuff you need everywhere
  • the view object itself is available in the template as view, so templates can access view methods and properties
  • Detail and List views don't just get the template variables object and object_list, they also get <model-name> and <model-name>_list
  • Permission decorators etc are better handled by django-braces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment