librelist archives

« back to archive

Question on add_url_rule and routes

Question on add_url_rule and routes

Harihara Vinayakaram
2013-07-06 @ 17:31
   The following code works

app = Flask(__name__)
class MyClass:
      def hello:
          print 'xxx'
          return 'xxx'

But when I try to do

class = MyClass()
app.add_url_rule('/', 'class.hello', class.hello)

The server starts up but when i hit the URL I get a 500 error . Can you
tell me where I am going wrong and how to debug this  I tried doing getattr
etc but did not succeed .

Thanks for the help


Re: [flask] Question on add_url_rule and routes

Steven Kryskalla
2013-07-06 @ 17:53
On Sat, Jul 6, 2013 at 10:31 AM, Harihara Vinayakaram <> wrote:
>       def hello:

That is not valid python, a function definition always has a list of
arguments. Also, since you defined this method inside of a class,
"self" needs to be first parameter of the method.

> class = MyClass()
> app.add_url_rule('/', 'class.hello', class.hello)

This does not work either, "class" is a keyword in python can not be
used as a variable name.

You can turn debug mode on to see what errors you're getting: