2014-03-27 16 views
1

兩個子文件夾位於稱爲前端的相同文件夾下。路由瓶服務器兩個子文件夾?

一個是應用程序,另一個是dist。

在我main.py

,我喜歡的路線以下

@bottle.route('/') 
def server_static(filename="index.html"): 
    return static_file(filename, root='./frontend/dist/') 

@bottle.route('/<filepath:path>') 
def server_static(filepath): 
    return static_file(file path, root='./frontend/dist/') 

現在,當用戶訪問主網站的網址一樣www.example.com/,他們可以成功地從文件夾dist下加載everyting。

但我希望爲文件夾應用添加特定的路由。這樣當用戶訪問www.example.com/dev/時,文件夾應用程序的所有內容都將被加載。

我已經試過

@bottle.route('/dev') 
def server_static(filename="index.html"): 
    return static_file(filename, root='./frontend/app/') 

@bottle.route('/dev/<filepath:path>') 
def server_static(filepath): 
    return static_file(file path, root='./frontend/app/') 

但這根本不起作用。我認爲這是由於我使用了filepath。

任何人都可以在這種情況下請教如何路由?

回答

0

當兩條路線匹配時,首先選擇一條。您需要首先聲明你的最具體路線:

@bottle.route('/') 
... 

@bottle.route('/dev') 
... 
@bottle.route('/dev/<filepath:path>') 
... 

# because this matches the previous two routes, it must come after them 
@bottle.route('/<filepath:path>') 
... 
+0

奇怪的是我仍然得到錯誤如下 「INFO 2014年3月27日13:59:21853 server.py:593]默認:」 GET/dev的HTTP/1.1 「304 - 」即使我遵循序列。有什麼建議? – Bob

+0

304很好。這意味着您的瀏覽器已經有一個靜態文件的副本 – Eric