【问题标题】:webapp2 subdomain routing for any domain任何域的 webapp2 子域路由
【发布时间】:2012-11-23 21:36:19
【问题描述】:

我想设置一个包罗万象的子域路由系统,其中子域是用户的配置文件,域可以是任何东西,因此不必根据运行它的服务器进行设置。

我现在拥有的不是路由,我只是尝试使用正则表达式来捕获子域之后的所有内容。

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

所以我希望能够转到类似 username.preset-sub.localhost.com/ 的页面并将其路由到该处理程序。

【问题讨论】:

    标签: google-app-engine routing webapp2 wildcard-subdomain


    【解决方案1】:

    我举了一个我正在开发的项目的例子,我必须用它来过滤发送 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'),
    ])
    

    如果您在网络上尝试,则必须在您的域的 cpanel 和应用程序的管理面板中添加 cname。更多信息:webapp2 - URI routing - Domain and subdomain routing

    【讨论】:

      猜你喜欢
      • 2015-10-01
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-18
      • 2021-02-25
      • 2021-07-09
      • 2014-04-24
      相关资源
      最近更新 更多