我是一名网络开发人员。noobie 和我正在整理一个简单的注册页面,作为在 GoogleApp Engine 上使用 Python 的练习。
当注册表单填写不正确时,程序可以正常工作。正确填写后,它应该重定向到感谢页面,但我收到服务器错误:
Internal Server Error
The server has either erred or is incapable of performing the requested operation.
Traceback (most recent call last):
File "/Users/bendavidow/Desktop/Stuff/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEng ine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1547, in __call__
return response(environ, start_response)
TypeError: 'unicode' object is not callable
我的问题有两个:(1)这个错误是什么意思?(2) 它来自哪里?
这是代码,减去html:
import webapp2
import re
import cgi
def escape_html(s):
return cgi.escape(s, quote = True)
class MainPage(webapp2.RequestHandler):
def write_form(self, username = "", email = "", username_error = "", password_error = "", verify_error = "", email_error = ""):
self.response.out.write(form %{"username": escape_html(username), "email": escape_html(email), "username_error": username_error, "password_error": password_error, "verify_error": verify_error, "email_error": email_error})
def get(self):
self.write_form()
def post(self):
username = self.request.get('username')
password = self.request.get('password')
verify = self.request.get('verify')
email = self.request.get('email')
username_check = re.search(r'^[a-zA-Z0-9_-]{3,20}$', username)
password_check = re.search(r'^.{3,20}$', password)
email_check = re.search(r'^[\S]+@[\S]+\.[\S]+$',email)
username_error, password_error, email_error, verify_error = "", "", "", ""
if not username_check:
username_error = "Invalid Username"
if not password_check:
password_error = "Invalid Password"
if email != '' and not email_check:
email_error = "Invalid Email"
if password != verify:
verify_error = "Passwords do not match"
if username_error or password_error or email_error or verify_error:
self.write_form(username, email, username_error, password_error, verify_error, email_error)
else:
return username
self.redirect("/thanks")
class ThanksHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write("Welcome " + username)
app = webapp2.WSGIApplication([('/', MainPage), ('/thanks',ThanksHandler)], debug = True)