create permenant unique links based on a user ID [duplicate]

混江龙づ霸主 提交于 2019-12-20 07:38:03

问题


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!


回答1:


Try this regular expression:

r'^/profile/\w*?-(\d+)$'

Though I also must tell you that this is a very bad idea!




回答2:


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() ).



来源:https://stackoverflow.com/questions/11256738/create-permenant-unique-links-based-on-a-user-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!