I am just getting to grips with jinja2 templating on GAE. What I am trying to do is to display a status msg in the rendered template without rendering the whole template again.
I have a webapp2 request handler which deals with sending a mail. In case of an error exception I would like to display a message on the page. Ditto if the mail has been sent successfully.
I render the template and pass the msg as a template value. I can see that this is not the way of doing things as the whole template renders again. What I want to do is simply pass the msg through.
class ContactoPage(webapp2.RequestHandler):
global template
template = jinja_environment.get_template('contacto.html')
def get(self):
self.response.out.write(template.render({'mail_status':''}))
def post(self):
userMail=self.request.get("emailFrom")
if not mail.is_email_valid(userMail):
self.response.out.write(template.render({'mail_status':'wrong mail address'}))
return
subject="Test Mail"
userMessage=self.request.get("emailBody")
message=mail.EmailMessage(sender="dennisargeomatica@gmail.com",subject="Test")
message.to=userMail
message.body=("Thank you! \n"
"Your mail: %s \n"
"Subject: %s \n"
"Message: %s \n"
%(userMail,subject,userMessage))
message.send()
self.response.out.write(template.render({'mail_status':'rudy, a msg to you'}))
Thx, Dennis