[英]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.