tags:

views:

72

answers:

1

The index route works when I go to /home/index

But it doesn't work why I type /home/test

What is wrong here, very confused!

import logging

from pylons import request, response, session, tmpl_context as c, url from pylons.controllers.util import abort, redirect

from helloworld.lib.base import BaseController, render

log = logging.getLogger(name)

class HelloController(BaseController):

def index(self):
    # Return a rendered template
    #return render('/hello.mako')
    # or, return a string
    return 'Hello World from index() action!'


def test(self):
return 'blah'

I get this error:

WebError Traceback:
⇝ NotImplementedError: Action u'test' is not implemented
View as:   Interactive  |  Text  |  XML (full)
URL: http://127.0.0.1:5000/hello/test
Module weberror.evalexception:431 in respond          view
>>  app_iter = self.application(environ, detect_start_response)
Module beaker.middleware:152 in __call__          view
>>  return self.wrap_app(environ, session_start_response)
Module routes.middleware:131 in __call__          view
>>  response = self.app(environ, start_response)
Module pylons.wsgiapp:107 in __call__          view
>>  response = self.dispatch(controller, environ, start_response)
Module pylons.wsgiapp:312 in dispatch          view
>>  return controller(environ, start_response)
Module helloworld.lib.base:15 in __call__          view
>>  return WSGIController.__call__(self, environ, start_response)
Module pylons.controllers.core:211 in __call__          view
>>  response = self._dispatch_call()
Module pylons.controllers.core:168 in _dispatch_call          view
>>  action)
NotImplementedError: Action u'test' is not implemented
+2  A: 

Double check your indentation. If def test(self) is on the same indentation level as the class, you won't get an indentation error.

This throws an indentation error:

class HelloController(BaseController):
    def index(self):
        return "hello from index()"

  def test(self):
        return "blah"

This doesn't:

class HelloController(BaseController):
    def index(self):
        return "hello from index()"

def test(self):
    return "blah"
cmoylan
interesting, but why does 'def index(..)' work? its at a different indentation??
Blankman
both my def's line up, the index works the other one doesn't.
Blankman
You could be mixing spaces and tabs. If you created your controller with "paster controller hello" the index method will be automatically created using 4 spaces for indentation. Your editor may be configured to insert a tab character that is 4 spaces in width. So even though everything lines up, one method is indented with spaces, the other with a tab.
cmoylan
@Chris, thanks I re-spaced the index and it worked, man!
Blankman
Awesome! Glad I could help.
cmoylan