2011-12-22 47 views
2

我使用bottlegevent爲我的python webdev實驗。 我的問題是我無法提供靜態文件,例如在我的模板中使用外部CSS。 我的文件夾結構爲:/static/css/style.css蟒蛇 - 瓶+ gevent不能提供靜態文件

我的代碼:

index.py

# -*- coding: UTF-8 -*- 
from gevent import monkey; monkey.patch_all() #patching default Python threads 
from bottle import mount, run, debug #initializing bottle 
from routes import root #importing site routes 
debug(True) 
run(app = root , host = '0.0.0.0' , port = 80 , server = 'gevent') 

routes.py

# -*- coding: UTF-8 -*- 
from bottle import * 
root = Bottle() 

@root.get('/static/<path:path>') 
def serve_files(path): 
    return static_file(path , root = '/static/') 

這是我的從終端回溯:

xxx.xxx.xxx.xxx - - [2011-12-22 09:36:44] "GET /static/css/style.css HTTP/1.1" 500 161 0.002867 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-linux-i686.egg/gevent/pywsgi.py", line 438, in handle_one_response 
    self.run_application() 
    File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-linux-i686.egg/gevent/pywsgi.py", line 424, in run_application 
    self.result = self.application(self.environ, self.start_response) 
    File "/usr/local/lib/python2.7/dist-packages/bottle-0.10.4-py2.7.egg/bottle.py", line 849, in __call__ 
    return self.wsgi(environ, start_response) 
    File "/usr/local/lib/python2.7/dist-packages/bottle-0.10.4-py2.7.egg/bottle.py", line 841, in wsgi 
    % (html_escape(repr(_e())), html_escape(format_exc(10))) 
NameError: global name '_e' is not defined 

請幫忙。

UPDATE:

我已經下載了瓶子的不穩定版(0.11版),並將其導入到我的腳本。現在有沒有500錯誤和回溯,但style.css中給了我404

[2011-12-22 12:42:59] "GET /static/css/style.css HTTP/1.1" 404 122 0.000591 
+0

['_e()'](https://github.com/defnull/bottle/blob/master/bottle.py#L38) – jfs 2011-12-22 10:54:20

+0

我不明白你的意見。你能否重複假裝? :) – bbrodriges 2011-12-22 12:07:52

+0

這似乎是'bottle.py'中的一個錯誤。定義'bottle._e = lambda:sys.exc_info()[1]'作爲解決方法。 – jfs 2011-12-22 12:31:42

回答

4

你的404,因爲可能你的根路徑,以靜態文件是錯誤的。

root='/static/'只有當您的根文件系統中有一個static文件夾時纔可以。可能它不是你真正擁有的。如果你有一個項目文件夾,並在這個文件夾中有一個static文件夾,使用root='./static/',它會正常工作。

+0

是的。謝謝。 – bbrodriges 2011-12-26 07:17:31

+0

@ bender.rodriges如果它是正確的標記爲答案 – gabeio 2012-06-18 03:00:51

+1

@gabeDel我完全忘了這麼做。謝謝。 – bbrodriges 2012-07-09 09:26:48