1👍
✅
request.POST
returns unicode strings by default. The next problem you are having is related to the encoding your supplying isn’t matching the declared encoding in the document you’re supplying.
doc = request.POST.get('xml','')
if not doc:
raise Exception()
h = etree.XML(doc.encode('ascii'), parser)
1👍
etree.parse
expects a filename (or a file object). There’s no file named <all your xml>
.
You need to feed the XML to the parser:
from lxml.cssselect import CSSSelector, etree
from lxml.etree import fromstring
if request.POST:
parser = etree.XMLParser(ns_clean=True, recover=True)
parser.feed(request.POST['xml'])
h = parser.close()
...
Or use fromstring
or XML
functions.
h = fromstring(request.POST['xml'], parser=parser)
or
h = etree.XML(request.POST['xml'], parser=parser)
- [Answered ]-One django project – render different content depending on domain
- [Answered ]-Django list of all possible error messages which a CharField form validator can raise?
- [Answered ]-Display superscript in Django Admin
- [Answered ]-Dynamically generate one value in a Django include tag
Source:stackexchange.com