您好我正在尝试制作一个注册页面并将其重定向到一个页面,上面写着感谢"用户名" 但是如何从注册页面获取用户名
import webapp2,re
form = """
<form method='post'>
<h1>signup</h1>
username: <input name='username' value='%(uname)s'><span style='color:red;'>%(erru)s</span><br>
password: <input name='password' type='password' value='%(pass)s'><span style='color:red;'>%(errp)s</span><br>
verfy password: <input name='verfy' type='password' value='%(verf)s'><span style='color:red;'>%(errv)s</span><br>
email (optional): <input name='email' value='%(em)s'><span style='color:red;'>%(erre)s</span><br>
<input type='submit'>
</form>
"""
def valid_username(username):
return re.match(r'^[a-zA-Z0-9_-]{3,20}$',username)
def valid_password(password):
return re.match(r'^[a-zA-Z0-9_- ]{3,20}$',password)
def valid_email(email):
return re.match(r'^[a-zA-Z0-9_]{3,20}[@][a-zA-Z][.]com$',email)
class Mainpage(webapp2.RequestHandler):
def write_form(self,username='',usererr='',password='',verfy='',vererr='',email='',emerr='',perr=''):
self.response.out.write(form%{'uname':username,'pass':password,'verf':verfy,'em':email,'errp':perr,'erru':usererr,'errv':vererr,'erre':emerr})
def get(self):
self.write_form()
def post(self):
usern = self.request.get('username')
userp = self.request.get('password')
userv = self.request.get('verfy')
userm = self.request.get('email')
self.redirect('/thanks')
class Thanks(webapp2.RequestHandler):
def post(self):
username = self.request.get('username')
self.response.out.write(username)
app = webapp2.WSGIApplication([('/',Mainpage),('/thanks',Thanks)],debug=True)
405 Method Not Allowed
The method GET is not allowed for this resource.
但是当我填写表单时,它会给我这条消息
答案 0 :(得分:1)
您可以将其作为GET参数添加到重定向网址:
self.redirect('/thanks?user=%s' % urllib.quote(self.request.get('username', 'new user')))