Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
解析 xml 文件的 python 脚本可以独立运行,但是当它在烧瓶中通过 views.py 调用时会引发错误。即使尝试从 views.py 本身解析 xml 文件也会引发错误。以下是几行引发错误的代码:
from lxml import etree doc1=etree.parse('file.xml')
错误:
IOError: Error reading file 'file.xml': failed to load external entity "file.xml"
您的“file.xml”文件在哪里?,将该文件放在 view.py 所在的位置
或者使用绝对路径
import os from lxml import etree ROOT_PATH = os.path.abspath(os.path.dirname(__file__)) file_path = ROOT_PATH + "/" + "file.xml" doc1 = etree.parse(file_path)