Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

How do you know what methods you can use/override in a CBV?

I love this idea of class based views but I feel like I'm super confused. How do you know what the methods are you can override in a class-based view?

It seems the template_name variable was just pulled out of nowhere. Is there documentation that lists everything like the functions you can override and all the variables you can override in a CBV? I looked through the django documentation but didnt really find what I was looking for, maybe I'm just looking in the wrong place. Thanks for any help

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The documentation is a bit spread out. The class based views API covers the list of class based views and mixins.

Googling from:docs.djangoproject.com/en/1.11/ref/class-based-views template_name may help narrow down the results.

Post back if you have more questions. Good Luck!!

Thanks!

Also I have a createView and I wanted to generate a word document with the python-docx library when a record gets created in the database. Just from a general level what do you think is the best way to go about that? Do I need to build my own mixin that I call in my createView? Or can I just create a subclass in my createView class? Sorry if these are dumb questions, I am very new to django

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

If the feature might be used in other views (or other projects! – always look to build for the future!) then a mixin seems appropriate!

No such thing as a dumb question! Best of luck!!