gpt4 book ai didi

python - 仅在生产中自定义模板标签的受限属性

转载 作者:行者123 更新时间:2023-11-28 23:00:40 25 4
gpt4 key购买 nike

我正在使用这个模板标签:

@register.filter
def php_striptags(text, allowed=""):
soup = BeautifulSoup(text)

# list all tags
allowed_tags = allowed.split()

for tag in soup.find_all(True):
if tag.name not in allowed_tags:
tag.unwrap()

return soup.encode_contents().decode('utf8')

它在开发机器上工作得很好,但我在生产机器上遇到这个错误:

Exception Type:     RuntimeError
Exception Value: restricted attribute
Exception Location: /usr/local/lib/python2.7/inspect.py in getargspec, line 813

我在 webfaction 上托管我的站点,使用 apache 和 mod_wsgi 运行。有什么问题吗?

最佳答案

终于找到了真正的问题,它实际上记录在 BeautifulSoup 文档中: http://www.crummy.com/software/BeautifulSoup/bs4/doc/#other-parser-problems

If your script works on one computer but not another, it’s probably because the two computers have different parser libraries available. For example, you may have developed the script on a computer that has lxml installed, and then tried to run it on a computer that only has html5lib installed. See Differences between parsers for why this matters, and fix the problem by mentioning a specific parser library in the BeautifulSoup constructor.

因此,要制作您的汤,请尝试以下方法:

soup = BeautifulSoup(text, "html.parser")

关于python - 仅在生产中自定义模板标签的受限属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com