单击我的登录/注销链接,它可以正常工作(重新加载页面,更新链接文本)。
我还有一个请求处理程序,它向我发送一封包含已提交表单输入值的电子邮件,然后加载同一页面。它似乎也正常工作(我收到了电子邮件,显示了正确的值)。
问题是,如果我在提交表单后单击相同的登录/注销,它就不起作用。它确实将我带到了登录页面,但最终进入了一个空白屏幕。它在地址栏中显示了我的应用程序的 url,但其他所有内容都是白色的。
import os
from google.appengine.ext.webapp import template
import cgi
import datetime
import urllib
import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail
class Greeting(db.Model):
author = db.StringProperty()
duties = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class e_mail(db.Model):
address = db.StringProperty()
def guestbook_key(guestbook_name= users.get_current_user()):
return db.Key.from_path('Guestbook', guestbook_name or 'default_guestbook')
class MainPage(webapp.RequestHandler):
def get(self):
guestbook_name=self.request.get('guestbook_name')
greetings_query = Greeting.all().ancestor(
guestbook_key(guestbook_name)).order('-date')
greetings = greetings_query.fetch(1000)
nickname = None
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'LOGOUT'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
path = os.path.join(os.path.dirname(__file__), 'about.html')
self.response.out.write(template.render(path, template_values))
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'LOGIN'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
path = os.path.join(os.path.dirname(__file__), 'about.html')
self.response.out.write(template.render(path, template_values))
class Email_SignUp(webapp.RequestHandler):
def post(self):
user = users.get_current_user()
guestbook_name=self.request.get('guestbook_name')
greetings_query = Greeting.all().ancestor(
guestbook_key(guestbook_name)).order('-date')
greetings = greetings_query.fetch(1000)
nickname = None
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'LOGOUT'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
e_mail.address = self.request.get('emailAdd')
path = os.path.join(os.path.dirname(__file__), 'about.html')
self.response.out.write(template.render(path, template_values))
mail.send_mail(sender="Do Not Reply <myemail@address.com>",
to="Do Not Reply <myemail@address.com>",
subject=e_mail.address,
body="""
Here is the test message
""")
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'LOGIN'
template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
e_mail.address = self.request.get('emailAdd')
path = os.path.join(os.path.dirname(__file__), 'about.html')
self.response.out.write(template.render(path, template_values))
mail.send_mail(sender="Do Not Reply <myemail@address.com>",
to="Do Not Reply <myemail@address.com>",
subject=e_mail.address,
body="""
Here is the test message
""")