可能重複:
create unique profile page for each user python創建permenant獨特聯繫
我使用谷歌的AppEngine Python和Jinja2的,並試圖給我的應用程序唯一的每個用戶沒有登錄的任何人都可以訪問他們的個人資料頁的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:我如何測試它我試着進入www.url.com/profile/ https://www.google.com/accounts/o8/id?id=AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56只是id =「這部分」是我放的,所以我會:
url = www.url.com/profile/AItOawlILoSKGNwU5RuTiRtXug1l8raLE45g-56
這就是我的嘗試,它並沒有很好的工作。先謝謝您的幫助!
它不是一個祕密的URL,我希望它是公開的。這就是全部原因,這樣每個人都可以看到它 – exployre
我在那裏做什麼?我不太清楚這意味着什麼...... – exployre