utwórz unikalną stronę profilu dla każdego pythona użytkownika
Używam silnika aplikacji Google w Pythonie z silnikiem szablonów Jinja2.
To może być głupie rozwiązanie, ale mam listę kilku tysięcy użytkowników i teraz mogą oni uzyskać dostęp tylko do własnych stron profilu i muszą być zalogowani, aby to zrobić. Chciałbym dać każdemu użytkownikowi unikalny adres URL dla jego strony profilu i zastanawiam się, jak to zrobić. Nie jestem pewien, czy to zadziała, ale czy coś takiego może być wykonalne?
class ProfilePage
userlist = GQL query to return all users in the system
user = users.get_by_id()
for user in userlist:
id = user.federated_id
posts = GQL query to return all posts by that user
self.render('/profile/id', posts=posts)
app = webapp2.WSGIApplication([('/', MainPage),
('/profile/([0-9]+)', ProfilePage),])
Mój HTML dla strony profilu wyświetla tylko nazwę użytkownika, a następnie wyświetla wszystkie ich ostatnie posty.
Aktualizacja:
Oto mój obecny kod, ale otrzymuję błąd 404:
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)
Jak mogę to przetestować? Próbowałem po prostu wprowadzić www.url.com/profile/https://www.google.com/accounts/o8/id?id=AItOawlILoSKGNwU5RuTiRtXug1l8raLEv5-mZg
Aktualizacja: Identyfikator, który pobierałem, nie był ich adresem URL OpenID, ale raczej identyfikatorem specyficznym dla aplikacji, który jest podawany przez każdego użytkownika, a zatem jest prawidłowy do użycia