[英]404 error on unique page creation with google app engine
I asked a similar question here: create permenant unique links based on a user ID but couldn't quite get an answer. 我在这里提出了类似的问题: 根据用户ID创建永久的唯一链接,但无法完全找到答案。 I am trying to give every user on my site a unique profile page.
我正在尝试为网站上的每个用户提供一个唯一的个人资料页面。 I have it mostly set up but I keep getting a 404 error.
我基本上已经设置好了,但我不断收到404错误。 Now I am not sure if it is a problem with my handler or just the whole way I am doing it.
现在我不确定是我的处理程序出现问题还是整个执行过程出现问题。
Here is my app code: 这是我的应用代码:
app = webapp2.WSGIApplication([('/', MainPage),
(r'/profile/(.+)', ProfilePage)])
and here is my ProfilePage handler class: 这是我的ProfilePage处理程序类:
class ProfilePage(webapp2.RequestHandler):
def get(self, profile_id):
profileowner = User.get_by_id(profile_id)
if profileowner:
#Get all posts for that user and render....
#theid is their federated_id
theid = profileowner.theid
personalposts = db.GqlQuery("select * from Post where theid =:1 order by created desc limit 30", theid)
#I collect this so that I can have their username in the top of the page
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)
else:
self.redirect("/")
For an ID of 1201, which I found in the datastore viewer for a use, I have been testing it by typing in www.url.com/profile/1201 and that is when I get the 404 error. 对于我在数据存储查看器中找到的ID 1201,我已经通过输入www.url.com/profile/1201对其进行了测试,那就是当我收到404错误时。
Update: It now is redirecting me to the main page with Amber's suggested change. 更新:现在,我将Amber建议的更改重定向到主页。
Now when I change this line: 现在,当我更改此行时:
profileowner = User.get_by_id(profile_id)
to this: 对此:
profileowner = User.get_by_id(17001)
it goes through correctly so I am guessing that that line is not correctly getting the profile_id from the URL 它正确通过,所以我猜测该行不能正确地从URL获取profile_id
r'/profile/<profile_id>'
is not a valid regular expression. 不是有效的正则表达式。 You probably want something like this instead:
您可能想要这样的东西:
r'/profile/(.+)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.