Django:如何确定 Django 不显示某些数据的原因?

发布于 2024-09-07 01:30:18 字数 316 浏览 0 评论 0原文

我有一个 Django 应用程序,它运行一个工具并使用 Django 模板将工具的结果显示给用户。有时 Django 不显示结果。它不会抱怨任何事情,只是不显示结果。我猜想这与结果中的一个或多个字符对于 Django 来说是非法的有关。我怎样才能获得有关 Django 不喜欢什么的更多信息?另外,有什么方法可以用来过滤掉“坏”字符吗?结果通常只是大量文本。它们包含公司机密内容,因此不幸的是我无法给出示例。我将 DEBUG 设置为 True,并将 TEMPLATE_DEBUG 设置为 DEBUG。

更新:

我添加了一些代码来过滤掉所有十进制值大于 127 的字符,现在它可以工作了。

I have a Django app that runs a tool and displays the results from the tool back to the user using a Django template. Sometimes Django does not display the results. It doesn't complain about anything, it just doesn't display the results. I'm guessing this is something to do with one or more of the characters in the results being illegal as far as Django is concerned. How can I get more information about what it is that Django doesn't like? Also, is there some method I can use to filter out "bad" characters? The results are normally just lots of text. They contain company confidential stuff, so I can't give an example unfortunately. I have DEBUG set to True and TEMPLATE_DEBUG set to DEBUG.

UPDATE:

I added some code to filter out all chars with a decimal value greater than 127 and it now works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一腔孤↑勇 2024-09-14 01:30:18

如果您使用的是开发服务器,请使用 pdb 设置断点,看看发生了什么。或者打印出您认为有“坏”字符的字符串。如果您不使用开发服务器,则可以使用 Python 日志记录模块来记录从该工具获取的字符串。

您可能会草率地得出关于包含不良字符的数据的结论。它可能是别的东西,并且在没有进一步调试的情况下很难推测。

If you are using the development server, put in a breakpoint with pdb and see what is going on. Or print out the string that you think has "bad" characters. If you aren't using the development server you could use the Python logging module to log the string you are getting from the tool.

You might be leaping to conclusions about the data containing bad characters. It may be something else, and without debugging further it is hard to speculate.

白昼 2024-09-14 01:30:18

您可以尝试使用内置的 django 编码方法来删除非法字符。

from django.utils.encoding import smart_str

smart_str(your_string)

you could try using the built in django encoding methods to remove illegal characters.

from django.utils.encoding import smart_str

smart_str(your_string)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文