我的main.py看起来像这样: -
#!/usr/bin/env python
import cgi
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import util
# imports for sending mail
from google.appengine.api import mail
from google.appengine.api import users
message = mail.EmailMessage(sender="Support <xyz@gmail.com>", subject="Email from")
message.to = "info <info@xyz.com>"
message.html = """
<html><head></head><body>
Dear <b>I</b>nfo: <br /><br />
message.<br /><br />
Please let us know if you have any questions.<br /><br />
The flxlmonline.com Support Team
</body></html>
"""
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write("""
<html>
<body>
<form action="/sign" method="post">
<p>
<label for="name">Name</label> <input type="text" name="name">
</p>
<p>
<label for="email">E-mail</label> <input type="email" name="email">
</p>
<p>
<label for="message">Message</label> <textarea name="message"></textarea>
</p>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
def post(self):
self.response.out.write('<html><body>You wrote:<pre>')
self.response.out.write(cgi.escape(self.request.get('message')))
self.response.out.write('</pre></body></html>')
**sendMail(self.request)**
def sendMail(request):
message.send()
application = webapp.WSGIApplication(
[('/', MainHandler),
('/sign', MainHandler)],
debug=True)
def main():
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
正如您所看到的,我正在尝试从post内部调用另一个名为sendEmail()的类方法。这给出了编译错误。知道我哪里错了吗?
提前致谢, BTR Naidu
答案 0 :(得分:1)
您正在将类方法视为函数。选择一个:
def sendMail(request):
message.send()
class MainHandler(webapp.RequestHandler):
def post(self):
sendMail(self.request)
或者:
class MainHandler(webapp.RequestHandler):
def sendMail(self):
# request = self.request
message.send()
def post(self):
self.sendMail()
答案 1 :(得分:0)
你试过吗?:
def post(self):
# ----
self.sendMail(self.request)
def sendMail(self, request):
message.send()