Django 调试控制台显示单页请求的双 GET
我正在运行开发人员的 Django 服务器,同时编写一个简单的视图,似乎每当我请求一个页面时,控制台都会显示同一 URL 有 2 个 GET。什么会导致这种情况发生?我没有使用任何重定向,所以我不知道如何发出第二个请求?
编辑:这似乎是由模板引起的。更改为模板的空白 html 文件解决了该问题。问题是为什么?我有多个 {% if %} {% endif %} 部分,没有其他部分。这会是一个问题吗?
I'm running the developer's Django server while writing a simple view and it seems whenever I request a page, the console shows that there are 2 GETs for the same URL. What would cause this happen? I'm not using any redirects, so I don't see how a 2nd request would be made?
EDIT: It appears to be caused by the template. Changing to a blank html file for a template resolved the issue. The question is why? I have multiple {% if %} {% endif %} sections, with no elses. Could that be an issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它也可能是遵循 WC3 指令的 Firefox,在该指令下,如果某些标签为空或损坏,例如没有 src="" 等,则应该双重加载。话虽这么说,我在收到时保存了渲染的 HTML 并移动它到一个静态文件中,我在其中添加了与实际结帐相同的标头和所有访问的小型数据库日志。
我只是偶然发现了这个问题并修复了它,删除了我的 img wit src=""
It also could be Firefox following a WC3 directive under which it's supposed to dual load if certain tags come empty or broken, for example, a without a src="" etc. That being said, I saved off the rendered HTML on receipt and moved it into a static file, where I added the same headers as the real checkout and a small DB log of all accesses.
I just stumble upon this problem and fixed it removing my img wit src=""
请确认 Django 是否在将斜杠附加到您的 url 后进行重定向。它由 settings.py 中的属性 APPEND_SLASH 控制。
Please confirm, if Django is redirecting after appending slash to your url. Its the property APPEND_SLASH in your settings.py controls that.
第二个请求可能是由错误配置的资产链接引起的 - 脚本、样式或 img 标记为空或省略了初始
/
,因此重新请求页面。The second request is probably caused by a mis-configured asset link - a script, style or img tag which is empty or omits the initial
/
and is therefore re-requesting the page.它可能是您的快捷方式/图标
您的页面模板中是否有链接 rel="shortcut icon" ?注释掉看看是否删除了第二个请求
It could be your shortcut/favicon
Do you have link rel="shortcut icon" in your page template? Comment it out to see if it removes the second request
就我而言:我在 2 个文件中有相同的 javascript 代码:一个在基本模板中,相同的代码在另一个模板中。当我使用 ajax 不重新加载所有页面时,我收到了 2x、4x、8x 调用,...
解决方案是仅在 mybase.html 中使用 javascript 代码
以下是我的js代码:
In my case : I have the same javascript code in 2 files : one in the base template and the same one in another template. As I use ajax to not reload all the page I got the call 2x, then 4x, and 8x, ...
The solution is the use the javascript code only in mybase.html
Hereafter my js code :