我一直在尝试使用web.py在Google App Engine上运行一个简单的网络应用,但一直遇到一些非常基本的错误。我搜索了网站,但没有找到任何解决我的问题的方法。以下是我正在尝试运行的代码的大纲:
import web
urls = (
"/","Index"
)
app = web.application(urls,globals())
render = web.template.render('pages/', base="layout")
class Index:
def GET(self):
#code...
if __name__ == "__main__":
app.cgirun()
这是app.yaml代码:
application: #appname
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: home.app
- url: /static
static_dir: static
但是我在日志中得到了这个:
2013-08-22 06:11:13 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', 'C:\\.....\\root\\home-gae']"
INFO 2013-08-22 06:11:16,956 devappserver2.py:557] Skipping SDK update check.
WARNING 2013-08-22 06:11:16,976 api_server.py:317] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2013-08-22 06:11:17,006 api_server.py:138] Starting API server at: http://localhost:64510
INFO 2013-08-22 06:11:17,013 dispatcher.py:164] Starting module "default" running at: http://localhost:8080
INFO 2013-08-22 06:11:17,019 admin_server.py:117] Starting admin server at: http://localhost:8000
ERROR 2013-08-22 10:11:24,303 wsgi.py:235]
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 223, in Handle
result = handler(dict(self._environ), self._StartResponse)
AttributeError: application instance has no __call__ method
INFO 2013-08-22 06:11:24,313 module.py:593] default: "GET / HTTP/1.1" 500 -
AttributeError使我感到困惑,因为在web /应用程序模块中似乎确实存在调用方法。有任何想法吗?任何想法都将不胜感激。
答案 0 :(得分:1)
我找到了解决问题的方法。
import web
urls = (
"/.*", "hello"
)
application = web.application(urls, globals())
#app = web.application(urls, globals())
class hello:
def GET(self):
return "HelloWorld"
#app = app.gaerun()
#app.cgirun()
app = application.wsgifunc()
使用“app = application.wsgifunc()”,然后代码就可以正常运行。
答案 1 :(得分:0)
首先,你的app.yaml有点问题。您需要将静态处理程序放在catch-all处理程序之前:
handlers:
- url: /static
static_dir: static
- url: /.*
script: home.app
否则,您将无法提供静态文件。
要修复网站未加载的问题,看起来开发服务器正在尝试将您的CGI应用视为WSGI应用。尽量让home.py
个文件适合the official example for web.py on GAE。也就是说,摆脱if __name__ == "__main__:"
部分,只需将其替换为:
app = app.gaerun()