在 Bottle Web 服务器上呈现多个文件

Rendering multiple files on bottle web server

我正在尝试在 Bottle Web 服务器上渲染几个文件。第一个 HTML 文件有一个链接到另一个文件的按钮。所以我需要这两个到服务器上的运行。 我的(更新的)项目结构是这样的

   -app.py
   -static
         -css
               bootstrap.css
               bootstrap.min.css
         -fonts
         -js
               jquery.js
               etc etc

  -index.html    
  -visualization.html

我的 index.html 文件必须先渲染。用户必须从中选择单击将他带到 visualization.html.

的按钮

我的页面没有呈现。这可能是什么原因?

来自 app.py 的路由片段如下所示:

from bottle import route, run, template, static_file, response, request

@route('/noob')

    def map():
        return static_file('index.html',root = './static')
    run(host='0.0.0.0', port='8030')

这就是我在 index.html:

中访问这些文件的方式
<script src="./static/js/jquery.js"></script>

  <link href="./static/css/grayscale.css" rel="stylesheet">

我对 PythonBottle 比较陌生。这是正确的吗?我收到 404 错误

另外,如何将两个文件放在瓶子服务器上。如上所述,index.html 中的按钮链接到 visualization.html。所以我猜这也应该是 运行ning 在 Bottle 服务器上。我 运行 它在同一个文件中吗?不同的端口?

提前致谢。

您需要将 index.html 放入 static 文件夹中。

-app.py
-static
     various css and img files being used in my two html files
     index.html    
     visualization.html

访问静态文件和模板的更好方法是将 index.html 重命名为 index.tpl,例如这个:

-app.py
    -static
       -js
         bootstrap.min.js (example)
       -css
       -fonts
 index.tpl    
 visualization.tpl
 profile.tpl

并且:

from bottle import route, run, template, static_file, response, request

@route('/noob')
def map():
    return template('index.tpl')

@route('/profile')
def profile():
    return template('profile.tpl')

@route('/static/<filepath:path>')
def server_static(filepath):
    return static_file(filepath, root='./static/')

run(host='0.0.0.0', port='8030')

并且在您的 tpl 文件中使用如下路径:

<script src="/static/js/bootstrap.min.js"></script>

希望这能回答您的问题。