Error when calling the function from the python file

I am trying to call the function from the python file into the page template and I am receiving this error .

We’re sorry, but there seems to be an error…
Here is the full error message:

Display traceback as text

Traceback (innermost last):

Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module, line 14, in call
Module Products.Five.browser.metaconfigure, line 485, in call
Module Products.Five.browser.pagetemplatefile, line 125, in call
Module Products.Five.browser.pagetemplatefile, line 59, in call
Module zope.pagetemplate.pagetemplate, line 132, in pt_render
Module, line 93, in call
Module, line 163, in render
Module chameleon.zpt.template, line 261, in render
Module chameleon.template, line 191, in render
Module chameleon.template, line 171, in render
Module, line 406, in render
Module, line 1223, in render_master
Module, line 420, in render_content
Module, line 378, in __fill_content_core
AttributeError: 'SimpleViewClass from /home/ananth/Plone/zinstance/' object has no attribute 'the_title'

  • Expression: "python: view.the_title()"
  • Filename: ...
  • Location: (line 19: col 18)
  • Source:
  • Arguments: repeat: {...} (0)
    template: <ViewPageTemplateFile - at 0x7fa394f39a50>
    views: <ViewMapper - at 0x7fa394505290>
    modules: <instance - at 0x7fa3a1778098>
    args: <tuple - at 0x7fa3aa077050>
    here: <ImplicitAcquisitionWrapper news at 0x7fa3942911e0>
    user: <ImplicitAcquisitionWrapper - at 0x7fa38f9eb0f0>
    nothing: <NoneType - at 0x5598d59ce560>
    container: <ImplicitAcquisitionWrapper news at 0x7fa3942911e0>
    request: <instance - at 0x7fa3943dfe60>
    wrapped_repeat: <SafeMapping - at 0x7fa39452ac58>
    traverse_subpath: <list - at 0x7fa3943df290>
    default: <object - at 0x7fa3a9f96550>
    loop: {...} (0)
    context: <ImplicitAcquisitionWrapper news at 0x7fa3942911e0>
    view: <SimpleViewClass from /home/ananth/Plone/zinstance/src/ demoview at 0x7fa394505150>
    translate: <function translate at 0x7fa39432fe60>
    root: <ImplicitAcquisitionWrapper Zope at 0x7fa3980cfb40>
    options: {...} (0)
    target_language: <NoneType - at 0x5598d59ce560>




class DemoView(BrowserView):
    def the_title(self):
        return u'A list of great trainings:'


  <p tal:content="python: view.the_title()"></p>

It seems the class for the view is not being taken into account.

See, it's supposed to mention your view class instead of SimpleViewClass.

Try mentioning only the class in the ZCML (ie remove the template attribute) and execute the template explicitly in the class code, like this:

from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class MyView(BrowserView):
    index = ViewPageTemplateFile("")
    def render(self):
        return self.index()
    def __call__(self):
        return self.render()