本文介绍了AttributeError:'function'对象没有属性'user_id'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用GAE(使用Python)制作一个网络应用程序,但是我一直在向数据存储区输入表单(名称,班级年份,生物)的一些问题。这实际上用于之前的工作,但不再是;我不太确定这里发生了什么事情。这是我的控制器和模板。我得到的错误是:
文件/ base / data / home / apps / p〜clubs-cs50 /
identity = user.user_id(),AttributeError:'function'对象没有属性'user_id'
任何帮助表示赞赏。
控制器:
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,$ b $'logout_link':users.create_logout_url('/'),
'nickname':DEFAULTif user 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('/豪我')
template:
< form method =post>
< pre>
输入您的首选名称< input type =textname =name>
输入您的班级年份< input type =textname =year>
< textarea name =biorows =10cols =51>在这里输入一个短的生物。 < / textarea的>
< input type =submit>
< / pre>
< / form>
解决方案
在第133行,改为:
user = users.get_current_user()
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>
解决方案
On line 133, do this instead:
user = users.get_current_user()
这篇关于AttributeError:'function'对象没有属性'user_id'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!