request.is_ajax()==单击“返回"按钮时为true? [英] request.is_ajax() == True when clicking back button?
问题描述
我有一个Django应用,该应用根据页面请求是否为Ajax返回不同的响应.
I have a Django app that returns different responses based on whether the page request is Ajax or not.
当我查看页面时,导航至其他地方,然后单击后退"按钮,该请求将呈现为 request.is_ajax()
的值为True.因此,JSON输出显示在浏览器中,而不是生成的HTML.
When I view a page, navigate elsewhere, then click the back button, the request gets rendered as if the value for request.is_ajax()
is True. So the JSON output is showing up in the browser rather than the generated HTML.
为什么会发生这种情况,我该如何预防呢?
Why might this be happening and how can I prevent it?
这是在Chrome(16.0.912.77)中发生的情况
This is happening in Chrome (16.0.912.77)
令人困惑的是,我实际上是在后台 am 对该URL发出ajax请求.基本上,我重载了URL,以便它既可以以格式化的HTML显示内容,又可以以JSON形式提供(以便随着时间的推移发生更改,我可以实时更新THML页面).最令人沮丧的是,最简单的解决方案是为Ajax版本创建一个单独的Django url模式.
Confusing matters is that I actually am making ajax requests of that URL in the background. Basically, I overloaded an URL so that it both displays the content in formatted HTML but also makes it available as JSON (so as changes happen overtime I can update the THML page in real time). It may be that the easiest solution, frustrating as it is, is to create a separate Django url pattern for the Ajax version.