谷歌应用引擎错误 - TypeError:此构造函数不带参数

时间:2014-07-23 11:12:18

标签: python google-app-engine

追溯

  Traceback (most recent call last):
 File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
  rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1101, in __call__
  handler = self.handler(request, response)
 TypeError: this constructor takes no arguments

html代码

   <form name="input" action="/addData" method="post" autocomplete="off">
              <div>
                  <label > Abbr</label>
                  <input type="text"  name="abbr" autocomplete="off" maxlength="20"/>
              </div>
              <div>
                  <label > Desc</label>
                  <input type="text"  name="desc" autocomplete="off" maxlength="200"/>
              </div>
              <div>
                  <button type="submit" >Add Data Entry </button>
              </div>
    </form>

的app.yaml

version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: MySQLdb
version: "latest"
- name: jinja2
version: "latest"

python文件 - &gt;

 JINJA_ENV = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
 autoescape=True, extensions=['jinja2.ext.autoescape'])


 class AddData:
  @login_required
  def post(self):
    abbr = self.request.get('abbr')
    desc = self.request.get('desc')

app = webapp2.WSGIApplication([
('/addData', AddData)
], debug=True)

我主要是尝试复制webform的google hello world示例,但我似乎无法理解问题所在。

1 个答案:

答案 0 :(得分:2)

您的AddData课程应该延长webapp2.RequestHandler

class AddData(webapp2.RequestHandler):
  @login_required
  def post(self):
    ...