我是一名python新手,並開始在Google App Engine上使用Bottle web框架。我一直在搞超級小,超級簡單的Hello World示例,並且已經遇到了問題。嘿。我終於得到了代碼這個工作......關於導入的新手python錯誤
import bottle
from bottle import route
from google.appengine.ext.webapp import util
@route('/')
def index():
return "Hello World!"
util.run_wsgi_app(bottle.default_app())
我的問題是,我想我可能只是去「瓶進口」沒有第二行。但是如果我把第二行寫出來,我會得到一個NameError。或者如果我'從瓶子導入*',我仍然得到錯誤。瓶子在我的網站的根目錄中只是一個名爲'bottle.py'的文件。因此,不管這些工作....
import bottle
from google.appengine.ext.webapp import util
@route('/')
def index():
return "Hello World!"
util.run_wsgi_app(bottle.default_app())
或者
from bottle import *
from google.appengine.ext.webapp import util
@route('/')
def index():
return "Hello World!"
util.run_wsgi_app(bottle.default_app())
該錯誤消息我得到的是...
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 3180, in _HandleRequest self._Dispatch(dispatcher, self.rfile, outfile, env_dict) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 3123, in _Dispatch base_env_dict=env_dict) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 515, in Dispatch base_env_dict=base_env_dict) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2382, in Dispatch self._module_dict) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2292, in ExecuteCGI reset_modules = exec_script(handler_path, cgi_path, hook) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2188, in ExecuteOrImportScript exec module_code in script_module.dict File "/Users/tyler/Dropbox/sites/dietgrid/code2.py", line 4, in @route('/') NameError: name 'route' is not defined
所以我錯在想它應該能夠以其他方式工作還是不行?
太棒了,謝謝。 – TylerW 2010-03-16 16:37:49