2016-05-02 39 views
2

我想呈現瓶子web服務器上的幾個文件。第一個HTML文件有一個鏈接到另一個文件的按鈕。所以我需要這些在服務器上運行。 我(更新)項目結構是這樣的在瓶子web服務器上呈現多個文件

-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瓶子。這是正確的嗎?我得到一個404錯誤

此外,如何將兩個文件放在瓶服務器上。如上所述,index.html中的按鈕鏈接到visualization.html。所以我猜這也應該在Bottle服務器上運行。我是否在同一個文件中運行它?不同的端口?

在此先感謝。

回答

2

您需要將index.html置於靜態文件夾中。

-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> 

希望這能回答你的問題。

+0

我做到了。只有我的html被渲染。 CSS不是。它爲CSS,JS和img文件拋出404錯誤。 – RJP

+0

我更新了答案 –

+0

現在服務器本身不運行。 – RJP

相關問題