AttributeError: 'function' object has no a

2019-09-06 09:45发布

I'm using GAE (in Python) to make a web app, but I have been bumping into some problems with inputting a form (name, class year, bio) into the datastore. This actually used to work before, but not anymore; I'm not too sure what event went wrong here. Here are my controller and template. The error I've been getting is:

File "/base/data/home/apps/p~clubs-cs50/1.389022909265479577/main.py", line 136, in post
    identity=user.user_id(), AttributeError: 'function' object has no attribute 'user_id'

Any help is appreciated. Thanks!

Controller:

class CreateProfileHandler(webapp2.RequestHandler):
    def get(self):
        user = users.get_current_user()
        template = JINJA_ENVIRONMENT.get_template('templates/profile_form.html')
        self.response.write(template.render({'user': user,
             'logout_link': users.create_logout_url('/'),
             'nickname': "DEFAULT" if not user else user.nickname(),
             'login_link': users.create_login_url('/')}))

    def post(self):
        user= users.get_current_user
        person = Person(
            name=self.request.get('name'),
            identity=user.user_id(),
            userID=user.user_id(),
            email=user.email(),
            year=self.request.get('year'),
            bio=self.request.get('bio'))
        person.put()
        self.redirect('/home')

template:

<form method = "post">
  <pre>
  Enter your preferred name <input type="text" name="name">
  Enter your class year <input type="text" name="year">
  <textarea name="bio" rows="10" cols="51"> Enter a short bio here. </textarea>
  <input type = "submit">
</pre>
</form>

1条回答
Rolldiameter
2楼-- · 2019-09-06 10:15

On line 133, do this instead:

user = users.get_current_user()
查看更多
登录 后发表回答