[英]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">
我对Python和Bottle比较陌生。 这是正确的吗? 我收到404 错误
.
另外,如何在瓶子服务器上放置两个文件。 如上所述, index.html
的按钮链接到visualization.html。 所以我猜这也应该在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>
希望这能回答你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.