ajax - GAE + Python2.7 + webapp2 + AJAX

标签 ajax google-app-engine python-2.7 webapp2

有没有关于GAE + Python2.7 + webapp2的AJAX实现的教程或代码示例。

我已尝试按照以下说明操作:

http://code.google.com/appengine/articles/rpc.html

但我收到以下错误:

Traceback (most recent call last):
  File "E:\dev\workspace\test\webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "E:\dev\workspace\test\webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "E:\dev\workspace\test\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "E:\dev\workspace\test\webapp2.py", line 1101, in __call__
    handler = self.handler(request, response)
TypeError: __init__() takes exactly 1 argument (3 given)

这里还有一个类似的讨论:

Google App Engine Python Protorpc Error: __call__() takes exactly 1 argument (3 given)

这是我在 Specialscope 示例中的代码:

主.py

from BaseHandler import BaseHandler  
from google.appengine.ext import blobstore  
from google.appengine.ext.webapp import blobstore_handlers  
import logging  
from google.appengine.api import files  
from google.appengine.api import images  
import json  
import webapp2

class FileuploadHandler(BaseHandler):  
   def get(self):  
     blobstore.create_upload_url('/static')  
     context={}  
     self.render_response("uploader.html",**context)  
class FileDownloadHandler(blobstore_handlers.BlobstoreUploadHandler,BaseHandler):  
   def post(self):  
     upload_files=self.request.POST  
     #image=upload_files['file']  
     logging.error(upload_files)  
     keys=upload_files.keys()  
     imageurls=[]  
     for key in keys:  
       if key.find("uploadimage")!=-1:  
         image=upload_files[key]  
         file_name=files.blobstore.create(mime_type='image/jpg')  
         with files.open(file_name,'a') as f:  
           f.write(image.value)  
         files.finalize(file_name)  
         blob_key=files.blobstore.get_blob_key(file_name)  
         imageurls.append(images.get_serving_url(blob_key))  
     context={}  
     context['imagelinks']=imageurls  
     self.response.write(json.dumps(context))  

app = webapp2.WSGIApplication([
      ('/upload',                     FileuploadHandler),
      ('/download',                   FileDownloadHandler),
      ], debug = True)     

BaseHandler.py

import webapp2
import os

from webapp2_extras import jinja2
from google.appengine.ext import db


class BaseHandler(webapp2.RequestHandler):

    @webapp2.cached_property
    def jinja2(self):
        # Returns a Jinja2 renderer cached in the app registry.
        return jinja2.get_jinja2(app=self.app)

    def render_response(self, _template, **context):
        # Renders a template and writes the result to the response.
        rv = self.jinja2.render_template(_template, **context)
        self.response.write(rv)

最佳答案

堆栈跟踪表明您的 WSGIApplication 中有一个 url 映射,其中有一个组,但是没有具有相应参数的处理程序。

如果你有

(r'/foo/(\s+)/(\s+)', FooHandler),

那么你需要

class FooHandler(webapp2.RequestHandler):
  def get(self, arg1, arg2):
    ...

您使用的文档比 Python 2.7 支持早了几年。如果我处在您的位置,我很想让应用程序首先在 Python 2.5 上运行,然后移植到 2.7。

关于ajax - GAE + Python2.7 + webapp2 + AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9550257/

相关文章:

ajax - 浏览器是否使用 CA 为 CORS Ajax 请求验证 SSL key ?

javascript - 不更新模态主体

php - 如何使 php 后端与 HTML 前端通信?

java - 让 GAE Shiro 和 Resteasy 协同工作

java - 了解 Google Cloud Platform 上的实例小时数

java - 使用 appengine 开发服务器 (java) 测试邮件

javascript - 如果使用 jquery ajax 验证器返回 true,则提交表单

python - 下载Qiime到CentOS6.4。 python版本有问题

python-2.7 - 谷歌云 json 预测请求中的 "Request payload size exceeds the limit"

python - Python 逻辑表达式中的奇怪转换