4

サブドメインがユーザーのプロファイルであり、ドメインが実行されているサーバーに基づいて設定する必要がないため、ドメインは何でもかまいません。

私が今持っているのはルーティングではありません。サブドメインの後のすべてをキャッチするために正規表現を使用しようとしました。

routes.DomainRoute('<subdomain>.preset-sub.<.*>', [
                webapp2.Route('/<page_url:\w+>', handler = SubHandler),
            ]),

したがって、username.preset-sub.localhost.com/ のようなページに移動して、そのハンドラーにルーティングできるようにしたいと考えています。

4

1 に答える 1

4

私が開発しているプロジェクトの例を挙げましたが、URL を送信するサブドメインをフィルタリングするために使用する必要がありました。

app = webapp2.WSGIApplication([

    routes.DomainRoute('api.domain.com', [
        webapp2.Route('/', handler=HomeApi, name='subdomain-home'),
        webapp2.Route('/user', handler=UserApi, name='subdomain-home'),

    ]), 
    routes.DomainRoute('web.domain.com', [
        webapp2.Route('/', handler=HomeApi, name='subdomain-web-home'),
        webapp2.Route('/login', handler=Login, name='login-home'),
        webapp2.Route(r'/products/<product_id:\d+>', ProductHandler),
    ]), 
    webapp2.Route('/', handler=Home, name='home'),
    webapp2.Route('/contact', handler=Contact, name='home'),
])

Web で試す場合は、ドメインの cpanel とアプリケーションの管理パネルに cname を追加する必要があります。詳細: webapp2 - URI ルーティング - ドメインおよびサブドメインのルーティング

于 2012-12-07T19:50:17.903 に答える