[英]Rendering multiple files on bottle web server
I am trying to render a couple of files on Bottle web server.我正在尝试在 Bottle Web 服务器上呈现几个文件。 The first HTML file has a button which links to another file.
第一个 HTML 文件有一个链接到另一个文件的按钮。 So I need both of these to run on the server.
所以我需要这两个在服务器上运行。 My (updated)Project structure is something like this
我的(更新的)项目结构是这样的
-app.py
-static
-css
bootstrap.css
bootstrap.min.css
-fonts
-js
jquery.js
etc etc
-index.html
-visualization.html
My index.html
file has to be rendered first.我的
index.html
文件必须首先呈现。 From which the user has to option to click on a button which takes him to visualization.html
.用户必须从中选择单击一个按钮,将他带到
visualization.html
。
My pages are not rendering.我的页面没有呈现。 What could be the reason for this?
这可能是什么原因?
The routing snippet from app.py is as show below: 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')
This is how I access those files in my index.html
:这是我在
index.html
访问这些文件的方式:
<script src="./static/js/jquery.js"></script>
<link href="./static/css/grayscale.css" rel="stylesheet">
I'm relatively new to Python and Bottle .我对Python和Bottle比较陌生。 Is this right?
这是正确的吗? I get a 404 error
我收到404 错误
. .
Also, how to I place two files on the bottle server.另外,如何在瓶子服务器上放置两个文件。 As explained above, a button in
index.html
links to visualization.html.如上所述,
index.html
的按钮链接到visualization.html。 So I'm guessing this should also be running on Bottle server.所以我猜这也应该在Bottle服务器上运行。 Do I run it in the same file?
我在同一个文件中运行它吗? Different port?
不同的端口?
Thanks in advance.提前致谢。
You need to put index.html in static folder.您需要将index.html放在static文件夹中。
-app.py
-static
various css and img files being used in my two html files
index.html
visualization.html
A better way for accessing static files and templates would be to rename index.html to index.tpl like this:访问静态文件和模板的更好方法是将index.html重命名为index.tpl,如下所示:
-app.py
-static
-js
bootstrap.min.js (example)
-css
-fonts
index.tpl
visualization.tpl
profile.tpl
And:和:
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')
And in your tpl files use path like this:在你的 tpl 文件中使用这样的路径:
<script src="/static/js/bootstrap.min.js"></script>
Hope this answers your question.希望这能回答你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.