google app engine - Partial page render, use webapp2 post request handler to pass a msg -


i getting grips jinja2 templating on gae. trying display status msg in rendered template without rendering whole template again.

i have webapp2 request handler deals sending mail. in case of error exception display message on page. ditto if mail has been sent successfully.

i render template , pass msg template value. can see not way of doing things whole template renders again. want pass 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, msg you'})) 

thx, dennis

paul collingwood (not durham cricketer assume) pointed me in right direction suggesting should solved ajax call. coming asp.net background got used update panels , looking similar technology within jinja2 framework. doesn't seem exist. thankfully, ajax calls jquery dead simple. make call javascript on client side so:

function mailservice() { mailfrom = $('#tbfrom').val(); mailmsg = $('#tbmail').val(); $.ajax({     type : 'post',     url : 'mailservice',     data : {         mailfrom:mailfrom,         mailmsg:mailmsg     },     success: function(response) {         $('#mailstatus').html(response);     } })} 

this mailservice webapp2 requesthandler on serer sends response after dealing mails:

class mailservice(webapp2.requesthandler):  def post(self):     mailfrom = self.request.get('mailfrom')     mailmsg = self.request.get('mailmsg')     if not mail.is_email_valid(mailfrom):         self.response.write('wrong mail address')         return     message=mail.emailmessage(sender='dennisargeomatica@gmail.com',subject='your mail argeomatica')     message.to=mailfrom     message.body=('thank you, have received mail. \n'                   'message: %s \n'                    %(mailmsg))     message.send()     self.response.write('mail sent') 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -