Using Google App engine for python/html web posting and sending automated email
Quick question, I m developing (n learning) a simple app whereby the user posts a comment to my webapp on GAE, and i will reply with an automated email (in Python).. Not sure where i got it wrong but was wondering whether anyone can help or guide me along?
Done a quick code snippets with some modifications from code.google.com
from google.appengine.ext import webapp
from google.appengine.api import mail
class MyRequestHandler(webapp.RequestHandler):
def get(self):
self.response.out.write('''
<html>
<body>
<form action="post">
<p>Name: <input type="text" name="name" /></p>
<p>Email: <input type="test" name="email" /></p>
<p>Comments / Inputs: <input type="text" name="comments" /></p>
</form>
</body>
</html>
''')
def post(self):
开发者_如何学JAVA name = self.request.get("name")
comment = self.request.get_range("comment")
message = mail.EmailMessage(sender="Support <contactus@support.com>",
subject="Thanks for your feedback")
message.to = self.request.get("email")
message.body = """
Hi there,
Thanks for your comment. We will get back to you soon.
Please let us know if you have any questions.
"""
message.send()
I think ur indentation is wrong. Also give ids to ur input elements Try this
from google.appengine.ext import webapp
from google.appengine.api import mail
class MyRequestHandler(webapp.RequestHandler):
def get(self):
self.response.out.write('''
<html>
<body>
<form action="post">
<p>Name: <input type="text" name="name" id="name" /></p>
<p>Email: <input type="test" name="email" id="email" /></p>
<p>Comments / Inputs: <input type="text" name="comments" /></p>
</form>
</body>
</html>
''')
def post(self):
name = self.request.get("name")
comment = self.request.get_range("comment")
message = mail.EmailMessage(sender="Support <contactus@support.com>",
subject="Thanks for your feedback")
message.to = self.request.get("email")
message.body = """
Hi there,
Thanks for your comment. We will get back to you soon.
Please let us know if you have any questions.
"""
message.send()
Looks like you've mixed up the action and method form attributes. Try:
<form action="<your url here>" method="post">
精彩评论