根据用户ID创建永久唯一链接 [英] create permenant unique links based on a user ID

查看:101
本文介绍了根据用户ID创建永久唯一链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:


我将google appengine与python和jinja2结合使用,并试图为我的应用中的每个用户提供一个唯一的URL给他们的个人资料页面,任何人都可以在不登录的情况下访问他们。

  class ProfilePage(webapp2.RequestHandler):
def get(self,profile_id):
user = User.get_by_id profile_id)
#profile_id =一些独特的字段
如果用户:
#获取该用户的所有帖子并呈现....
theid = user.theid
personalposts = db.GqlQuery(select * from Post where theid =:1 order by created desc limit 30,theid)
else:
personalposts = None
全局访问
logout = users.create_logout_ur l(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:我如何测试它我尝试只输入www.url.com/profile/ https://www.google.com/accounts/o8/id?id=AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56 只是将id =这个部分就是我所说的我会:

  url = www.url.com/profile/AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56 

这就是我所尝试的,并没有完全奏效。感谢您的帮助!

解决方案

您正在使用的网址(www.url.com/profile/ AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56 )url的最后部分是实体的完整键,而代码中使用实体id加载它(使用get_by_id())。

Possible Duplicate:
create unique profile page for each user python

I am using google appengine with python and jinja2 and trying to give each user in my app a unique URL to their profile page that can be visited by anyone without logging in. Here is my code thus far:

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),])

When I try and test it it just gives me a 404 error. I suppose if the code is right I might be using the wrong testing URL. For example if this is their OpenID ID: How can I test it out I tried just entering www.url.com/profile/https://www.google.com/accounts/o8/id?id=AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56 would just the id="this part" be what I put so I would have:

url = www.url.com/profile/AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56

That's what I tried and it didn't quite work. Thanks in advance for the help!

解决方案

The url that your are using (www.url.com/profile/AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56) the last part of the url is a full key to the entity while in the code your are using the entity id to load it (using get_by_id() ).

这篇关于根据用户ID创建永久唯一链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆