Reputation: 1111
I have my main.py looking like this:-
#!/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 <[email protected]>", subject="Email from")
message.to = "info <[email protected]>"
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()
As you can see, I am trying to call another class method called sendEmail() from inside post. This gives compilation error. Any idea where I am going wrong?
Thanks in advance, BTR Naidu
Upvotes: 2
Views: 189
Reputation: 12838
You're treating a class method like a function. Choose one:
def sendMail(request):
message.send()
class MainHandler(webapp.RequestHandler):
def post(self):
sendMail(self.request)
Or:
class MainHandler(webapp.RequestHandler):
def sendMail(self):
# request = self.request
message.send()
def post(self):
self.sendMail()
Upvotes: 1
Reputation: 35961
Did you tried with?:
def post(self):
# ----
self.sendMail(self.request)
def sendMail(self, request):
message.send()
Upvotes: 0