偶尔出现错误的网址
我们有一个基于 python/django 构建的应用程序。每当链接缺失 (404) 或服务器错误 (500) 时我都会收到电子邮件。我注意到我收到了一些看起来像这样的链接:
Referrer: http://www.mywebsite.com/model/
Requested URL: /model/js/modernizr-1.7.min.cb14102011.js
User agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB7.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
IP address: 41.2.246.84
问题是请求的网址。它请求相对于当前目录的js文件,而不是绝对目录。奇怪的是我无法重现它,而且这种情况每天都会发生几次,即使该网站上有很多不同的用户。缺少链接的结果有时还会导致 500 个错误,具体取决于 url(由于我为应用程序定义的 django url 结构)。
以前有人见过这种问题吗?我应该检查哪些内容可以解决此问题?
编辑: js文件通过 http://www.mywebsite.com/static/js/ 访问相同的配置适用于 css 文件。经过进一步调查,似乎“静态”部分已从网址中删除。
编辑 (2) 我昨天犯了一个错误。 {{ STATIC_URL }} 不仅不会按照设置文件中的定义进行提取,而且会被替换为当前(相对)url。即,在原来的帖子中“模型”应该是“静态”,但它没有被替换。我仍然不知道为什么会发生这种情况。
We have an application running built on python/django. I get emails whenever there is a missing link (404) or a server error (500). I've noticed that i get a number of links that looks something like this:
Referrer: http://www.mywebsite.com/model/
Requested URL: /model/js/modernizr-1.7.min.cb14102011.js
User agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB7.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
IP address: 41.2.246.84
The issue is the requested url. It requests the js file relative to the current dir, rather than the absolute dir. What makes it bizarre is that I can't reproduce it, and it happens a handful of times a day, even though there are many different users on the site. The consequence of the missing links also sometimes causes 500 errors, depending on the url (due to the django url structure I've defined for the application).
Has anybody seen this kind of issue before? Is there anything that I should check for that might resolve this issue?
Edit:
The js files are accessed through http://www.mywebsite.com/static/js/ The same configuration applies for css files. On further investigation it seems that the 'static' part gets dropped from the url.
Edit (2)
I made a mistake yesterday. not only does the {{ STATIC_URL }} not pull through as defined in the settings file, it is replaced with the current (relative) url. I.e, in the original post "model" should be "static", but its not replaced as such. I'm still at a loss as to why this happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢丹尼斯和乔丹。你的评论对我帮助很大。
对于我的场景,我注意到问题仅发生在 1 个网址上。由于许多模板使用相同的基本模板。我排除了基本模板问题。我还检查了 url 的视图,以查看上下文是否已正确添加(因为没有上下文,STATIC_URL 变量可能无法通过)。一切都好。
我也只在日志中看到IE7。当我查看模板时,我注意到一个额外的结束符“(即 class="bogus"" )。我认为额外的引用弄乱了模板,然后 IE7 就无法渲染模板的其余部分。
我已经在生产中进行了更改,因此不能 100% 确定我已经解决了问题,但我会在一天左右的时间内知道。
编辑:
我意识到,答案在于,如果存在编码问题(即服务器抛出 500),则上下文无法正确加载,因此 STATIC_URL 不会被填充。这也意味着对于从 STATIC_URL 加载的任何文件,每个 500 错误都会有一个相应的 404 错误
Thanks Dennis and Jordan. Your comments helped me a lot.
For my scenario I noticed the problems only happens on 1 url. Since many of the templates use the same base template. I ruled out a base template problem. I also checked the views of the url to see that the context was added correctly (since without context the STATIC_URL variable might not pull through). All good.
I also only saw IE7 in the logs. When I looked at the template I noticed an extra closing " (ie class="bogus"" ). I think that extra quote messed up the template, and IE7 then had trouble rendering the rest of the template.
I've made the changes in production so am not 100% sure that I've fixed the problem, but I'll know within a day or so.
Edit:
The answer, I've realised, lies in the fact that if there is a coding problem (ie the server throws a 500), then the context doesn't get loaded correctly, and so the STATIC_URL doesn't get populated. This also means that each 500 error will have a corresponding 404 error for any files loaded from STATIC_URL