# -*- coding: UTF-8 -*-
import google
print google.__path__.append("C:\Program Files(x86)\Google\google_appengine")
import webapp2
form ="""
<form method ="post" action= "/testform">
<input name="q">
<input type="submit">
</form>
"""
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['ContentType'] = 'text/plain'
self.response.out.write(form)
class TestHandler(webapp2.RequestHandler):
def get(self):
q = self.request.get("q")
self.response.out.write(q)
app = webapp2.WSGIApplication([
('/', MainPage),
('/testform',TestHandler),
], debug=True)
当我运行这个简单的应用程序时,它会显示文本区域和提交但是当我提交时我得到500错误。在电源外壳上,我得到以下内容: -
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named not_found
INFO 2017-01-14 21:16:13,831 module.py:806] default: "POST /testform HTTP/1.1" 500 -
答案 0 :(得分:2)
我猜你使用 app.yaml 就是一个例子in Google AppEngine Docs。
如果从app.yaml中删除以下两个linse,则可以修复。
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
script: home.app
- url: /index\.html
script: home.app
- url: /stylesheets
static_dir: stylesheets
- url: /(.*\.(gif|png|jpg))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg)$
- url: /admin/.*
script: admin.app
login: admin
- url: /.* // <- delete this
script: not_found.app // <- delete this
答案 1 :(得分:1)
您的代码中存在一些缩进错误,并且您需要post
方法来处理表单响应。请参阅下面的固定代码。
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['ContentType'] = 'text/plain'
self.response.out.write(form)
class TestHandler(webapp2.RequestHandler):
def post(self):
q = self.request.get("q")
self.response.out.write(q)
我不确定这会解决你所有的问题,但至少可以让你更接近。