如何抑制或禁用 reSTructuredText 中的警告?
我正在用Python开发一个CMS,它使用reStructuredText(通过docutils)来格式化内容。我的很多内容都是从其他来源导入的,通常以未格式化的文本文档的形式出现。 reST 对此非常有用,因为默认情况下它使一切看起来都很正常。
然而,我遇到的一个问题是,我收到的警告转储到我的网络服务器上的 stderr 并注入到我的页面内容中。例如,我在网页上收到如下警告:
系统消息:WARNING/2(第 296 行);反向链接
是:如何抑制、禁用或以其他方式重定向这些警告?
理想情况下,我希望将这些警告写入日志文件,但是如果有人可以告诉我如何关闭警告注入到我的内容中,那就完美了。
负责将 reST 解析为 HTML 的代码:
from docutils import core
import reSTpygments
def reST2HTML( str ):
parts = core.publish_parts(
source = str,
writer_name = 'html')
return parts['body_pre_docinfo'] + parts['fragment']
I'm working on a CMS in Python that uses reStructuredText (via docutils) to format content. Alot of my content is imported from other sources and usually comes in the form of unformatted text documents. reST works great for this because it makes everything look pretty sane by default.
One problem I am having, however, is that I get warnings dumped to stderr on my webserver and injected into my page content. For example, I get warnings like the following on my web page:
System Message: WARNING/2 (, line 296); backlink
My question is: How do I suppress, disable, or otherwise re-direct these warnings?
Ideally, I'd love to write these out to a log file, but if someone can just tell me how to turn off the warnings from being injected into my content then that would be perfect.
The code that's responsible for parsing the reST into HTML:
from docutils import core
import reSTpygments
def reST2HTML( str ):
parts = core.publish_parts(
source = str,
writer_name = 'html')
return parts['body_pre_docinfo'] + parts['fragment']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来
report_level
接受字符串是旧版本。现在,以下内容对我有用。关于level
根据上面的代码,你知道可以分配
self.report_level
(即settings_overrides={'report_level': ...}
)让警告不展示。我将其设置为
SERVER_LEVEL+1
,因此它不会显示任何错误。 (您可以根据您的需求进行设置。)It seems the
report_level
accept string is an old version. Now, the below is work for me.about level
According to the above code, you know that you can assign the
self.report_level
(i.e.settings_overrides={'report_level': ...}
) let the warning not show.and I set it to
SERVER_LEVEL+1
, so it will not show any error. (you can set it according to your demand.)