0

私はここで同様の質問をしました:ユーザーIDに基づいて永続的な一意のリンクを作成しますが、完全に答えを得ることができませんでした。私は自分のサイトのすべてのユーザーにユニークなプロフィールページを提供しようとしています。ほとんど設定していますが、404エラーが発生し続けます。今では、それが私のハンドラーの問題なのか、それとも私がやっている方法全体の問題なのかわかりません。

これが私のアプリコードです:

app = webapp2.WSGIApplication([('/', MainPage),
                               (r'/profile/(.+)', ProfilePage)])

これが私の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("/")

データストアビューアで使用するために見つけた1201のIDの場合、www.url.com / profile / 1201と入力してテストしており、404エラーが発生します。

更新:現在、Amberの提案された変更を含むメインページにリダイレクトされています。

この行を変更すると、次のようになります。

profileowner = User.get_by_id(profile_id)

これに:

profileowner = User.get_by_id(17001)

それは正しく通過するので、その行はURLからprofile_idを正しく取得していないと推測しています

4

1 に答える 1

1
r'/profile/<profile_id>'

は有効な正規表現ではありません。代わりに、おそらく次のようなものが必要です。

r'/profile/(.+)'
于 2012-06-30T18:59:43.590 に答える