Why is Webapp2 redirecting to the page but not reloading?

I use webapp2 in GAE when I called self.redirect to some page, as shown below:

self.redirect(some_url) 

which returned the page looks like a cached one, I need to refresh / reload the page to get the latest data.

Is there a cache setting for webapp2? or do I need to set some properties to respond to this page? Please inform.

+4
source share
4 answers

In my project, I fixed this by adding time.sleep(0.1) just before calling self.redirect('someurl') .

Not sure if this is the best way to solve the problem, but the pages started showing the latest information.


Edit: Beware of consistency issues

@Lindsay's answer will open. Using time.sleep(0.1) can give the expected result in a local environment, but you cannot trust it in a production environment. If you really want the results to be strictly consistent, use the ancestor's request, not time.sleep(0.1) .

+6
source

I assume this is because the previous page updates the object, which then accesses the later page using a non-parent query. A non-ancestral query provides final consistency, not strong consistency, so the problem is not that the page is not refreshing, but that it shows what the data looked like before the update was completed. When you update or add a call to the time.sleep () function, you can provide enough time for the data store to catch up, especially during testing. However, in production, your dream may not be long enough in all cases, and the same applies to refreshing the page.

If you test your application and find out that you are using a query that is not related to the ancestor, and therefore your problem is really possible - consistency and strong consistency, a Google search will show you that many pages discuss this topic; here's one: https://cloud.google.com/developers/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore#ftnt_ref1 .

The simplest solution is to create an entity group and use the ancestor's query, although this is due to a possible performance hit and the limitation of one update per second per entity group.

+5
source

I have the same problem that I did a trick that is not good, but helped me anyway. Called by a temporary viewer and then redirected to html:

 <meta http-equiv="refresh" content="0.5;URL='/'"> 

Hope this helps. anyone with a better answer?

+1
source

Do you call return immediately after self.redirect(some_url) ? Perhaps it gets into another code that displays the page.

0
source

Source: https://habr.com/ru/post/1484000/


All Articles