GAE python: success message or add HTML class after redirect
<p>I've a website with a contact form running on a google App Engine. After submitting I'd like to redirect and show a message to the user to let him know the message was sent, this can eighter be a alert message or adding a class to a html tag. How can I do that?</p>

<p>my python file looks like this:</p>

<pre><code>import webapp2
import jinja2
import os
from google.appengine.api import mail

jinja_environment = jinja2.Environment(autoescape=True,loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))

class index(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('index.html')
        self.response.write(template.render())

    def post(self):
        vorname=self.request.get("vorname")
        ...
        message=mail.EmailMessage(sender="...",subject="...")

        if not mail.is_email_valid(email):
            self.response.out.write("Wrong email! Check again!")

        message.to="..."
        message.body=""" Neue Nachricht erhalten:
        Vorname: %s
        ... %(vorname,...)

        self.redirect('/#Kontakt')

app = webapp2.WSGIApplication([('/', index)], debug=True)
</code></pre>

<p>I already tried this in my html file:</p>

<pre><code>&lt;script&gt;
    function sentAlert() {
         alert("Nachricht wurde gesendet");
    }
&lt;/script&gt;

&lt;div class="submit"&gt;
    &lt;input type="submit" value="Senden" onsubmit="return sentAlert()"   
     id="button-blue"/&gt;
&lt;/div&gt;
</code></pre>

<p>but it does it before the redirect and therefore doesn't work.
Does someone have an idea how to do that?</p>

<p>After the redirect a request <strong>different</strong> than the POST one for which the email was sent will be served.</p>

<p>So you need to <strong>persist</strong> the information about the email being sent across requests, saving it in the POST request handler code and retrieving it in the subsequent GET request handler code (be it the redirected one or any other one for that matter).</p>

<p>To persist the info you can, for example, use the user's session (if you already have one, see <a href="http://stackoverflow.com/questions/37134540/passing-data-between-pages-in-a-redirect-function-in-google-app-engine?noredirect=1">Passing data between pages in a redirect() function in Google App Engine</a>), or GAE's memcache/datastore/GCS. </p>

<p>Once the info is retrieved you can use it any way you wish.</p>

javascript python html google-app-engine