django-cms/djangocms-link

AttributeError: 'Instance' object has no attribute 'page'

jedie opened this issue · 1 comments

jedie commented

The get_link() method access self.page if internal link is used:

    def get_link(self):
        if self.internal_link:
            ref_page = self.internal_link
            link = ref_page.get_absolute_url()

            if ref_page.site_id != getattr(self.page, 'site_id', None):
                ref_site = Site.objects._get_site_by_id(ref_page.site_id).domain
                link = '//{}{}'.format(ref_site, link)

There is a warning in CMSPlugin():

    @property
    def page(self):
        warnings.warn(
            "Don't use the page attribute on CMSPlugins! CMSPlugins are not "
            "guaranteed to have a page associated with them!",
            DontUsePageAttributeWarning)
        return self.placeholder.page if self.placeholder_id else None

In my case i get a AttributeError: 'Instance' object has no attribute 'page'

An AttributeError in this case means that your plugin might not be correctly inheriting from CMSPlugin. That warning can be ignored but the attribute should always be there.

Indirectly fixed by #136