【问题标题】:Set Application Root in Web Application in bottle在瓶中的 Web 应用程序中设置应用程序根目录
【发布时间】:2019-02-12 16:34:49
【问题描述】:

如何为我在瓶中开发的应用程序设置应用程序根目录。

我已经这样写了我的瓶子应用程序

app = Bottle()

@route(path = '/GetMain')
def get_main_page():
  return static_file(...)

app.run(host=socket.getfqdn(), port=8080)

通过上面的代码,我可以像http://xxxx.com:8080/GetMain 一样检索我的页面。 但是如果我希望我的代码部署在http://xxxx.com:8080/dashboard/GetMain 下,我该如何更改我的应用程序根目录。 我不想更改我所有的 URL 和反应路径

【问题讨论】:

  • 你是如何部署你的应用程序的? mod_wsgi,gunicorn,...?
  • 我正在使用内置服务器进行部署。我在命令行上运行类似 python filename.py 的应用程序
  • 您可以使用 Web 服务器(nginx 或 apache2)轻松完成。这是你的选择吗?如果是这样,我会发布一个详细的答案。

标签: python-2.7 bottle


【解决方案1】:

你可以通过指定前缀来挂载它。

这是一个工作示例 sn-p。

import socket
from bottle import route, default_app


@route(path = '/GetMain')
def get_main_page():
  # Commenting out the below line for testing this snippet.
  # return static_file(...)
  return "Hello World"


if __name__ == '__main__':
    app = default_app()
    app.mount('/dashboard', app)
    app.run(host=socket.getfqdn(), port=8080)

请注意,我已经使用 python 3.5 对此进行了测试

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 2019-05-01
    • 2013-06-07
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多