0
點擊我的鏈接登錄/註銷,它工作正常(重新加載頁面,更新鏈接文本)。請求處理程序不工作
我也有一個請求處理程序,它向我發送一封包含提交表單輸入值的電子郵件,然後加載相同的頁面。它也似乎工作正常(我收到了電子郵件,顯示正確的值)。
問題是,如果我點擊相同的登錄/註銷後提交表單,它不起作用。它確實帶我到登錄頁面,但最後到了一個空白屏幕。它在地址欄中顯示我的應用的網址,但其他所有內容都只是白色。
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 <[email protected]>",
to="Do Not Reply <[email protected]>",
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 <[email protected]>",
to="Do Not Reply <[email protected]>",
subject=e_mail.address,
body="""
Here is the test message
""")