我正在尝试使用 Google App Engine 构建一个(新手)应用程序,但是当我运行它时,我发现这个(日志)错误我不明白:
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1479, in __init__
self.router = self.router_class(routes)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1129, in __init__
self.add(route)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1142, in add
for r in route.get_match_routes():
AttributeError: 'str' object has no attribute 'get_match_routes'
INFO 2012-04-29 14:42:34,056 dev_appserver.py:2891] "GET / HTTP/1.1" 500 -
整个代码如下。有人可以找出这个错误的原因以及我该如何解决它?提前感谢您的帮助!
import webapp2
form = """
<html>
<head>
<title>Sign Up</title>
<style type="text/css">
.label {text-align: right}
.error {color: red}
</style>
</head>
<body>
<h2>Signup</h2>
<form method="post">
<table>
<tr>
<td class="label">
Username
</td>
<td>
<input type="text" name="username" value="">
</td>
<td class="error">
</td>
</tr>
<tr>
<td class="label">
Password
</td>
<td>
<input type="password" name="password" value="">
</td>
<td class="error">
</td>
</tr>
<tr>
<td class="label">
Verify Password
</td>
<td>
<input type="password" name="verify" value="">
</td>
<td class="error">
</td>
</tr>
<tr>
<td class="label">
Email (optional)
</td>
<td>
<input type="text" name="email" value="">
</td>
<td class="error">
</td>
</tr>
</table>
<input type="submit">
</form>
</body>
</html>
"""
welcome = """
<html>
<head>
<title>Unit 2 Signup</title>
</head>
<body>
<h2>Welcome, %(username)s!</h2>
</body>
</html>
"""
import re
USER_RE = re.compile(r"^[a-zA-Z0-9_-]{3,20}$")
def valid_username(username):
return USER_RE.match(username)
PASS_RE = re.compile(r"^.{3,20}$")
def valid_password(password):
return PASS_RE.match(password)
EMAIL_RE = re.compile(r"^[\S]+@[\S]+\.[\S]+$")
def valid_email(email):
return EMAIL_RE.match(email)
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
def write_form(self, text_write):
self.response.out.write(form)
def post(self):
user_name = self.request.get("username")
user_pass = self.request.get('password')
user_verify = self.request.get('verify')
err_username = ""
if not valid_username(user_name):
err_username = "Oh no!!! Username isn't valid!"
err_pass = ""
if not valid_pass(user_pass):
err_pass = "Oh no!!! password isn't valid!"
err_verify = ""
if user_pass != user_verify:
err_verify = "Oh no!!! password verification didn't check!"
class WelcomeHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(welcome)
app = webapp2.WSGIApplication([('/', MainHandler), '/welcome', WelcomeHandler],
debug=True)