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 ploneconf.site.browser.views, 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 five.pt.engine, line 93, in call
Module z3c.pt.pagetemplate, 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 5fabce0489779f237a6f2c88e3f4b1ec.py, line 406, in render
Module e63f010bf7909f09a1c3d30bf47637c1.py, line 1223, in render_master
Module e63f010bf7909f09a1c3d30bf47637c1.py, line 420, in render_content
Module 5fabce0489779f237a6f2c88e3f4b1ec.py, 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: ... nf.site/src/ploneconf/site/browser/templates/demoview.pt
  • 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/ploneconf.site/src/ploneconf/site/browser/templates/demoview.pt demoview at 0x7fa394505150>
    translate: <function translate at 0x7fa39432fe60>
    root: <ImplicitAcquisitionWrapper Zope at 0x7fa3980cfb40>
    options: {...} (0)
    target_language: <NoneType - at 0x5598d59ce560>

browser/config.zcml

<browser:page
name="demoview"
for="*"
layer="zope.interface.Interface"
class=".views.DemoView"
template="templates/demoview.pt"
permission="zope2.View"
/>

browser/views.py

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

browser/templates/demoview.pt

  <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("my-template.pt")
    def render(self):
        return self.index()
    def __call__(self):
        return self.render()