× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Redirect to asset after post on Google App Engine, Python

Martijn Pieters
Jul 16, 2014
<p><strong>Q: What was the request about? </strong><br>Building a Google App Engine Python application, uploading assets with AJAX, where the response needed to redirect the browser to the newly created asset-specific URL.</p><p><strong>Q: How did you help with the request?</strong><br>I showed how a JSON response containing the new location could be returned instead of a 302 HTTP redirect. Based on the JSON response contents the browser can then be instructed to load the new location.</p><p>We also discussed how the Google NDB data store adds new data and when that new data is available to other requests (eventual consistency), discussing strategies to cope with the delay between writing to the store and seeing the data elsewhere.<br><br><strong>Q: Any best practices &amp; key learnings you can share?</strong><br>AJAX is not a 'regular' browser request / response pattern; it is not the browser page itself that you are loading so redirects don't apply to the page the user sees either. If you want to replace the current browser page after a redirect, you'll need to do so explicitly from the code handling the AJAX response.</p><p>As for the Google NDB store, there are options to ensure that data is found much faster, using a parent key. This lets you group data by a common parent, and other requests can get to that same data by reusing the group parent. There is a hefty throttle on this; you can instead have the user wait (with a polling browser page) or you can use Memcache to store the data for your application until such time the NDB has committed the data.</p>