{% extends "base-new.html" %} {% block header-content %}
Send messages to the user between pages.
When you instantiate the class, the attribute 'msg' will be set from the cookie, and the cookie will be deleted. If there is no flash cookie, 'msg' will default to None.
To set a flash message for the next page, simply set the 'msg' attribute.
Example psuedocode:
if new_entity.put(): flash = Flash() flash.msg = 'Your new entity has been created!' return redirect_to_entity_list()Then in the template on the next page:
{% filter escape %} {% templatetag openblock %} if flash.msg {% templatetag closeblock %}{% templatetag openvariable %} flash.msg {% templatetag closevariable %}{% templatetag openblock %} endif {% templatetag closeblock %} {% endfilter %}
{{ flash.msg }}
{% endif %}Welcome to the flash demo. You can Set flash data.
{% filter escape %}class FlashPage(webapp.RequestHandler): def get(self): self.flash = flash.Flash() if self.request.get('setflash') == "true": self.flash.msg = 'You set a flash message! Refresh this page and this message is gone!' print "Location: /flash\n\n" else: template_values = { 'flash': self.flash, } path = os.path.join(os.path.dirname(__file__), 'templates/flash.html') self.response.out.write(template.render(path, template_values)) {% endfilter %}