Django -- 弄乱测试服务器 -- 304 错误等等
在开发我的网络应用程序(需要登录整个网站)时,我注意到一个有趣的“故障”(如果你可以这样称呼它)。我正在查看我的 Django 站点,并在 Chrome 中登录到该站点(在测试服务器上)。然后我退出了我的网站并完全关闭了 Chrome。
然后我打开 Firefox 并将 URL 粘贴到我的 Django 站点,期望被带到登录页面。然而,我并没有被要求登录,而是已经登录了。所以我继续注销该网站并关闭 Firefox。
然后我重新打开Chrome登录,却发现没有CSS样式。我登录后,整个网站都失去了 CSS 样式,并且测试服务器一直给出所有 CSS 和 IMG 文件的 304
错误。
我发现 304
错误与时间不匹配有关(就像 Django 认为我已注销,但在 Firefox 中我已登录 - 所以现在很困惑)。
我只是想知道这是否可以避免,或者它是否是测试服务器的“功能”?这种事情在生产模式下也会发生吗?
编辑以明确我的要求:
当我在 Django 测试服务器上遇到 304 错误时,样式和图像是否会继续发生继续发生使用 Apache 启动 Web 应用程序?
谢谢!
While working on my webapp (which requires a login for the entire site) I noticed a funny "glitch" (if you can call it that). I was viewing my Django site, logged into the site (on the test server) in Chrome. I then logged out of my site and closed Chrome entirely.
I then opened Firefox and pasted in the URL to my Django site, expecting to be taken to the login page. However, I was not asked to log in, but rather was already logged in. So I proceeded to log out of the site and close Firefox.
I then re-opened Chrome to log in, only to find that there was no CSS styling. I logged in and the whole site had lost its CSS styling and the test server kept given the 304
errors for all CSS and IMG files.
I've figured out that the 304
error has something to do with time mis-matching (like Django thinking I was logged out, but in Firefox I was logged in -- so now it is confused).
I was just wondering if this is avoidable, or if it is a "feature" of the test server? Will this kind of thing happen in production mode too?
EDIT for clarity of what I'm asking:
Will the loss of styling and images due to the 304 error that I am experiencing with the Django test server continue to occur when I launch the webapp with Apache?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对三件事有疑问:
不幸的是,对于您看到的前两个问题,有很多可能的解释。很可能没有什么太严重的问题。
对于前两个问题,您可以尝试恢复到新状态,然后查看问题是否仍然出现。例如,使用干净的 Django 数据库(没有会话)并尝试清除所有缓存的浏览器信息(cookie、身份验证、缓存文件)。诚然,这是一种相当耗时的测试问题的方法,但这是我在无法直接检查您的情况的情况下可以给出的最佳一般建议。
幸运的是,304 响应根本不是问题。 304 仅表示浏览器的缓存中有该文件。请参阅条件视图处理:
You've got questions about three things:
Unfortunately there are quite a few possible explanations for the first two issues you're seeing. Most likely there's nothing too serious going wrong.
For the first two issues you could try reverting to a fresh state and then seeing if the problems still occur. e.g. Use a clean Django database (with no sessions) and try to clear all your cached browser information (cookies, auth, cached files). Admittedly this is quite a time consuming way to test for problems, but its the best general advice I can give without being able to examine your situation directly.
Luckily 304 responses aren't a problem at all. A 304 just means that the browser has the file in its cache. See Conditional View Processing: