Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get TypeError: get() takes exactly 2 arguments (1 given)? Google App Engine

I have been trying and trying for several hours now and there must be an easy way to retreive the url. I thought this was the way:

#from data.models import Program

import basehandler

class ProgramViewHandler(basehandler.BaseHandler):
    def get(self,slug):
#        query = Program.all()
#        query.filter('slug =', fslug)
        self.render_template('../presentation/program.html',{})

Whenever this code gets executed I get this error on the stacktrace:

appengine\ext\webapp__init__.py", line 511, in call handler.get(*groups) TypeError: get() takes exactly 2 arguments (1 given)

I have done some debugging, but this kind of debugging exceeds my level of debugging. When I remove the slug from def get(self,slug) everything runs fine.

This is the basehandler:

import os

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template



class BaseHandler(webapp.RequestHandler):
    def __init__(self,**kw):
        webapp.RequestHandler.__init__(BaseHandler, **kw)

    def render_template(self, template_file, data=None, **kw):
        path = os.path.join(os.path.dirname(__file__), template_file)
        self.response.out.write(template.render(path, data))

If somebody could point me in the right direction it would be great! Thank you! It's the first time for me to use stackoverflow to post a question, normally I only read it to fix the problems I have.

like image 877
Sam Stoelinga Avatar asked Jun 25 '10 16:06

Sam Stoelinga


2 Answers

You are getting this error because ProgramViewHandler.get() is being called without the slug parameter.

Most likely, you need to fix the URL mappings in your main.py file. Your URL mapping should probably look something like this:

application = webapp.WSGIApplication([(r'/(.*)', ProgramViewHandler)])

The parenthesis indicate a regular expression grouping. These matched groups are passed to your handler as arguments. So in the above example, everything in the URL following the initial "/" will be passed to ProgramViewHandler.get()'s slug parameter.

Learn more about URL mappings in webapp here.

like image 148
David Underhill Avatar answered Nov 14 '22 07:11

David Underhill


If you do this:

obj = MyClass()
obj.foo(3)

The foo method on MyClass is called with two arguments:

def foo(self, number)

The object on which it is called is passed as the first parameter.

Maybe you are calling get() statically (i.e. doing ProgramViewHandler.get() instead of myViewHandlerVariable.get()), or you are missing a parameter.

like image 20
Sjoerd Avatar answered Nov 14 '22 06:11

Sjoerd