AttributeError:' Doctype'对象没有属性' name'

时间:2015-01-24 16:09:20

标签: python django beautifulsoup minify

我正在使用django-htmlmin来缩小HTML。但是在生产服务器上获取AttributeError: 'Doctype' object has no attribute 'name'。但在我的开发环境中一切正常。 这是完整的追溯:

{'levelname': ERROR,'time':24/Jan/2015 16:59:02,'module': base,'process': 1716,'thread' :156 'message':Internal Server Error: /'}
Traceback (most recent call last):
  File "C:\Program Files\Bitnami\djangostack-1.7-0\apps\django\django\core\handlers\base.py", line 204, in get_response
    response = middleware_method(request, response)
  File "C:\Program Files\Bitnami\djangostack-1.7-0\python\lib\site-packages\htmlmin\middleware.py", line 44, in process_response
    parser=parser)
  File "C:\Program Files\Bitnami\djangostack-1.7-0\python\lib\site-packages\htmlmin\minify.py", line 39, in html_minify
    mini_soup = space_minify(soup, ignore_comments)
  File "C:\Program Files\Bitnami\djangostack-1.7-0\python\lib\site-packages\htmlmin\minify.py", line 61, in space_minify
    space_minify(child, ignore_comments)
  File "C:\Program Files\Bitnami\djangostack-1.7-0\python\lib\site-packages\htmlmin\minify.py", line 55, in space_minify
    if str(soup.name) in EXCLUDE_TAGS:
  File "C:\Program Files\Bitnami\djangostack-1.7-0\python\lib\site-packages\bs4\element.py", line 667, in __getattr__
    self.__class__.__name__, attr))
AttributeError: 'Doctype' object has no attribute 'name'

我一设置HTML_MINIFY = False。它解决了这个问题。有人可以帮助我。

1 个答案:

答案 0 :(得分:2)

通过将beautifulsoup升级到beautifulsoup4 == 4.3.2来解决

Issue。现在一切正常。