为每个用户python创建唯一的配置文件页面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了为每个用户python创建唯一的配置文件页面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2053字,纯文字阅读大概需要3分钟。
内容图文
![为每个用户python创建唯一的配置文件页面](/upload/InfoBanner/zyjiaocheng/695/4cf7480d2c554656b9d0e8d8a624dbe2.jpg)
我正在使用带有Jinja2模板引擎的python中的google app引擎.
这可能是一个愚蠢的解决方案,但是我有一个数千用户的列表,现在他们只能访问自己的个人资料页面,并且必须登录才能执行此操作.我想为每个用户的个人资料页面提供一个唯一的URL,我想知道如何做.我不确定这是否行得通,但是这样的事情可行吗?
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),])
我的个人资料页面HTML仅显示用户名,然后显示其所有最新帖子.
更新:
所以这是我当前的代码,但我刚遇到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)
我如何才能尝试我刚刚输入www.url.com/profile/https://www.google.com/accounts/o8/id?id=AItOawlILoSKGNwU5RuTiRtXug1l8raLEv5-mZg
更新:
我检索的ID不是他们的OpenID URL,而是每个用户都被赋予的应用程序特定ID,因此可以正确使用
解决方法:
一种简单的方法是为每个用户分配一个唯一的URL标识符(或使用其键名),这样您就可以通过用户的ID查询该用户或基于唯一的URL标识符属性进行查询.如果需要,还可以使用其federated_id.
例:
class User(ndb.Model):
unique_identifier = ndb.StringProperty()
...
class ProfilePage(webapp2.RequestHandler):
def get(self, profile_id):
#profile_id = key name of user
user = User.get_by_id(profile_id)
#profile_id = some unique field
#user = User.query(User.unique_identifier == profile_id).get()
if user:
#Get all posts for that user and render....
app = webapp2.WSGIApplication([('/', MainPage),
('/profile/<profile_id>', ProfilePage),])
内容总结
以上是互联网集市为您收集整理的为每个用户python创建唯一的配置文件页面全部内容,希望文章能够帮你解决为每个用户python创建唯一的配置文件页面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。