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 Django Class-based Views Customizing Class-based Views Mixins

Bas Kuunk
Bas Kuunk
21,308 Points

How to deal with Python2 and Super()?

So it is a common question. I am on my local machine, a MacBook Air (2011) with python2 pre-installed. Calling super() with no arguments gives me the following error:

TypeError at /teams/edit/1/ super() takes at least 1 argument (0 given)

  1. One solution I read was to include the class and self as two arguments in super(PageTitleMixin, self). This gives this error:

TypeError at /teams/edit/1/ must be type, not classobj

  1. Installing python3 should resolve this, but I cannot call manage.py with python 3: ModuleNotFoundError: No module named 'django.core.urlresolvers'

I cannot imagine that I'm the only one with this problem, yet I cannot find an easy solution. Advice is greatly appreciated. Thanks!

2 Answers

Python 2 is different from Python 3โ€”the version Treehouse teachesโ€”and many of Python 2's features are differently used than in Python 3. I recommend installing Python 3 on your computer.

I hope this helps!

Happy coding! :zap: ~Alex

This seems to work for me:

class PageTitleMixin(object):
    page_title = ""

    def get_page_title(self):
        return self.page_title

    def get_context_data(self, **kwargs):
        context = super(PageTitleMixin, self).get_context_data(**kwargs)
        context["page_title"] = self.get_page_title()
        return context