Why do I get TypeError: get () takes exactly 2 arguments (1 set)? Google app engine

I tried and tried for several hours, and there should be an easy way to get the URL. I thought it was like this:

#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 is executed, I get this error on the stack:

appengine \ ext \ webapp__init __. py ", line 511, in a call to handler.get (* group) TypeError: get () takes exactly 2 arguments (1 given)

I did some debugging, but such debugging exceeds my debugging level. When I remove the slug from def get (self, slug), everything works fine.

This is the basic manipulator:

 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 someone can point me in the right direction, that would be great! Thanks! This is the first time I use stackoverflow to post a question, usually I only read it to fix the problems that I have.

+6
python google-app-engine web-applications
source share
2 answers

You get this error because ProgramViewHandler.get() is 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)]) 

Brackets indicate a grouping of regular expressions. These mapped groups are passed to your handler as arguments. Thus, in the above example, everything in the URL after the initial "/" will be passed to the parameter ProgramViewHandler.get() slug .

Read more about webapp urls here .

+9
source share

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 to which it is called is passed as the first parameter.

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

+1
source share

All Articles