Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix this TypeError?

I'm new to python and Google App Engine. I'm trying to refactor this code from Nick Johnson blog to use webapp2 and python 2.7. http://blog.notdot.net/2009/10/Blogging-on-App-Engine-part-1-Static-serving

Anyways, when I run the code below I get this error.

TypeError: get() takes exactly 2 arguments (1 given)

I think it may have something to do with the path variable not being defined, but I don't know how to define it.

import webapp2
from google.appengine.ext import webapp
from google.appengine.ext import db

class StaticContent(db.Model):
    body = db.BlobProperty()
    content_type = db.StringProperty(required=True)
    last_modified = db.DateTimeProperty(required=True, auto_now=True)

def get(path):
    return StaticContent.get_by_key_name(path)

def set(path, body, content_type, **kwargs):
    content = StaticContent(
        key_name=path,
        body=body,
        content_type=content_type,
        **kwargs)
    content.put()
    return content

class MainHandler(webapp2.RequestHandler):

    def get(self, path):
        content = get(path)
        if not content:
            self.error(404)
            return
app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)
like image 884
Busilinks Avatar asked May 19 '26 05:05

Busilinks


1 Answers

The error is raised because the get method of the MainHandler class expects a path parameter.
You should add grouping to the regex in your routing definition to pass the path parameter to the get method:

app = webapp2.WSGIApplication([('(/.*)', MainHandler)],
                              debug=True)
like image 127
systempuntoout Avatar answered May 23 '26 01:05

systempuntoout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!