【发布时间】:2012-06-30 16:29:32
【问题描述】:
我正在使用带有 python 和 jinja2 的 google appengine,并尝试为我的应用程序中的每个用户提供一个指向其个人资料页面的唯一 URL,任何人无需登录即可访问该 URL。到目前为止,这是我的代码:
class ProfilePage(webapp2.RequestHandler):
def get(self, profile_id):
user = User.get_by_id(profile_id)
#profile_id = some unique field
if user:
#Get all posts for that user and render....
theid = user.theid
personalposts = db.GqlQuery("select * from Post where theid =:1 order by created desc limit 30", theid)
else:
personalposts = None
global visits
logout = users.create_logout_url(self.request.uri)
currentuser = users.get_current_user()
self.render('profile.html', user = currentuser, visits = visits, logout=logout, personalposts=personalposts)
app = webapp2.WSGIApplication([('/', MainPage),
('/profile/([0-9]+)', ProfilePage),])
当我尝试测试它时,它只会给我一个 404 错误。我想如果代码是正确的,我可能使用了错误的测试 URL。例如,如果这是他们的 OpenID ID:我如何测试它p>
url = www.url.com/profile/AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56
这就是我尝试过的方法,但效果不佳。提前感谢您的帮助!
【问题讨论】:
标签: python google-app-engine jinja2 user-profile webapp2