Can';“得不到”;使用AJAX启用客户端RPC请求”;使用python 2.7在google应用程序引擎上进行演示
我从来没有用AJAX做过任何事情,只是用javascript做了一些基本的事情,而我的python经验更多的是科学方面的。也就是说,我在google app engine上的网站开发进展顺利,直到我开始尝试创建ajax功能的演示 我在GAE网站上找到了这个,但它似乎不起作用。这篇文章可能会很长,因为我想解释我所经历的障碍。非常感谢您提供的任何帮助或见解,无论是关于如何修复此演示还是使用不同的ajax方法 作为参考,我正在使用带有Python 2.7的Google应用程序引擎,运行32位Ubuntu 12.04。另外,我知道有人就这个问题询问了其他人,但我没有找到令人满意的答复 因此,从演示开始,我将必需的Can';“得不到”;使用AJAX启用客户端RPC请求”;使用python 2.7在google应用程序引擎上进行演示,python,ajax,google-app-engine,rpc,webapp2,Python,Ajax,Google App Engine,Rpc,Webapp2,我从来没有用AJAX做过任何事情,只是用javascript做了一些基本的事情,而我的python经验更多的是科学方面的。也就是说,我在google app engine上的网站开发进展顺利,直到我开始尝试创建ajax功能的演示 我在GAE网站上找到了这个,但它似乎不起作用。这篇文章可能会很长,因为我想解释我所经历的障碍。非常感谢您提供的任何帮助或见解,无论是关于如何修复此演示还是使用不同的ajax方法 作为参考,我正在使用带有Python 2.7的Google应用程序引擎,运行32位Ubunt
index.html
、main.py
和app.yaml
文件复制到名为get
的目录中。按照说明,我还创建了一个子目录,static
,在其中我放入了一份json2.js
(演示中说可以在找到,但我只能在找到)。因此,我的项目结构如下所示:
-dir:get
-app.yaml
-main.py
-index.html
-dir static:
-json2.js
application: get
version: 1
runtime: python
api_version: 1
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.py
def main():
app = webapp.WSGIApplication([
('/', MainPage),
('/rpc', RPCHandler),
], debug=True)
util.run_wsgi_app(app)
if __name__ == '__main__':
main()
通过一切设置,我启动我的Web服务器:
chris@thinkpad:~/code/get$ python ~/google_appengine/dev_appserver.py ./
这将成功启动。但是,当我将浏览器指向http://localhost:8080/
我收到一个导入错误:
File "/home/chris/code/get/main.py", line 6, in <module>
from django.utils import simplejson
ImportError: No module named django.utils
我的新2.7版本如下所示。注意添加了threadsafe:true
、将main.py
转换为main.app
以及添加了库
参数
application: get
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
libraries:
- name: django
version: latest
同样,我成功地启动了appserver。现在,指向http://localhost:8080/
引发以下错误:
ImportError: <module 'main' from '/home/chris/code/get/main.pyc'> has no attribute app
对其进行处理,使其更友好一点,用以下内容替换整个代码块、函数和所有内容:
app = webapp.WSGIApplication([
('/', MainPage),
('/rpc', RPCHandler),
], debug=True)
重新启动appserver并再次指向http://localhost:8080/
,我终于看到了页面:
不幸的是,传奇还在继续。我重新启动appserver,获取以下打印输出:
chris@thinkpad:~/code/get$ python ~/google_appengine/dev_appserver.py ./
INFO 2013-05-25 16:18:28,097 sdk_update_checker.py:244] Checking for updates to the SDK.
INFO 2013-05-25 16:18:28,322 sdk_update_checker.py:272] The SDK is up to date.
INFO 2013-05-25 16:18:28,354 api_server.py:153] Starting API server at: http://localhost:56101
INFO 2013-05-25 16:18:28,375 dispatcher.py:164] Starting server "default" running at: http://localhost:8080
INFO 2013-05-25 16:18:28,385 admin_server.py:117] Starting admin server at: http://localhost:8000
然后单击“添加”按钮。这引发了一个错误,我在下面完整地打印了这个错误,我不能完全弄清楚:
INFO 2013-05-25 16:18:37,633 server.py:585] default: "GET / HTTP/1.1" 200 3597
INFO 2013-05-25 16:18:37,989 server.py:585] default: "GET /static/json2.js HTTP/1.1" 304 -
INFO 2013-05-25 16:18:38,164 server.py:585] default: "GET /favicon.ico HTTP/1.1" 404 154
ERROR 2013-05-25 16:18:41,469 webapp2.py:1528] __init__() takes exactly 1 argument (3 given)
Traceback (most recent call last):
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1076, in __call__
handler = self.handler(request, response)
TypeError: __init__() takes exactly 1 argument (3 given)
ERROR 2013-05-25 16:18:41,471 wsgi.py:235]
Traceback (most recent call last):
File "/home/chris/google_appengine/google/appengine/runtime/wsgi.py", line 223, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/chris/google_appengine/lib/webapp2-2.3/webapp2.py", line 1076, in __call__
handler = self.handler(request, response)
TypeError: __init__() takes exactly 1 argument (3 given)
INFO 2013-05-25 16:18:41,479 server.py:585] default: "GET /rpc?action=Add&arg0=%221%22&arg1=%222%22&time=1369498721460 HTTP/1.1" 500 -
在这一点上,我被卡住了。任何关于如何让这个演示正常运行的想法,或者是让我的web应用程序ajaxy更好的方法,都将不胜感激
任何关于如何让这个演示正常运行的想法,或者是让我的web应用程序ajaxy更好的方法,都将不胜感激
因为在这里发布一个完整的应用程序有点过火,所以我决定放一个。这不会立即解决您的问题,但会有助于实现这一概念。我建议您首先使用webapp2和WSGI,通过GAE开始使用Python27:看起来您离此越来越近了。与大多数其他谷歌演示一样,这对于连接ajax演示来说过于复杂。我理解展示一些安全含义的愿望,但他们可以更简单地完成这个演示(在谷歌代码网站上翻译每个演示)。