Django URL 解析基础设施停止工作
我们最近推出了一个由 Django 驱动的新网站,但我们遇到了最奇怪的错误:
该网站在 Apache 下使用 mod_fastcgi 运行。暂时一切正常,然后 URL 标记和 reverse() 功能停止工作。它们没有返回预期的 URL,而是返回“”。
我们没有在 Apache 的日志文件中注意到任何内容; Django 没有生成任何错误。而且(最重要的是)这个问题只发生在生产模式下;当 DEBUG=True 时我们无法重现它。
关于我们应该在哪里寻找问题有什么想法吗?
更新:事实证明这是settings.LANGUAGES的问题,尽管我们还没有确定到底为什么会造成问题。
We recently launched a new Django-powered website, and we are experiencing the oddest bug:
The site is running under Apache with mod_fastcgi. Everything works fine for a while, and then the URL tag and reverse() functionality stops working. Instead of returning the expected URL, they return "".
We haven't noticed anything in Apache's log file; there are no errors being generated by Django. And (the kicker) the problem only occurs in production mode; we can't reproduce it when DEBUG=True.
Any thoughts on where we should be looking for the problem?
Update: It turned out to be a problem with settings.LANGUAGES, although we haven't determined exactly why that broke things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前也遇到过这种情况。通常这是由于 urls.py 文件“损坏”造成的。有两件事使得这种错误很难修复:
调试:解决这个问题的方法是手动禁用所有应用程序(只需在 INSTALLED_APPS 中注释掉它们的行)并检查reverse()是否有效。如果它仍然有效,那么我会启用下一个应用程序,直到它损坏为止。我知道,非常基本的东西,但它有效:)
This has happened to me before. Normally it's due to a 'broken' urls.py file. There are two things that make this kind of bug really hard to fix:
Debugging: The way I go around fixing this is by manually disabling all applications (just comment out their line in INSTALLED_APPS) and checking reverse() works. If it still works, then I enable the next app, until it breaks. I know, very rudimentary stuff, but it works :)
在非调试模式的环境中匹配 url 时,Django 会出现奇怪的行为。
例如,使用 DEBUG=False,Django 将忽略以下网址:
特别是在上面的情况下,您可以让字符串为空:
换句话说,检查您的正则表达式。
你能把你的urls.py放在这里进行分析吗?
Django has a odd behaviour when matching urls in a environment that isn't under debug mode.
For example, with DEBUG=False, Django will ignore urls such as:
specifically in the case above, you could let the string empty:
In other words, check your regexes.
Can you put your urls.py here to be analyzed?