[Flask] Trying to pass XML through to an HTML template
Dunlap, Zachariah
ZDunlap at ap.org
Wed Dec 2 12:07:22 EST 2015
Hi all,
I'm sure I'm missing something but I haven't had any luck figuring out what, perhaps someone here can point me in the right direction.
I have the module below which I'm using to get and XML item from a URL, read it and return elements and values to an HTML template.
The itemid and description variables render in the template just fine, the one that I'm having an issue with is the XML I need to send through to a textarea on the template. I've tried rendering it as a string, escaping it & encoding it but have had no luck getting it passed through.
I've tested getting this XML in a simple module and I know it returns content but the module for this applicattion can't see that value, it comes back as 'None'.
Any guidance on how I can pass XML through to the textarea would be greatly appreciated.
MODULE:
@app.route('/updateitem', methods=['GET'])
def updateitem():
url = 'http://xmldocument.fake'
url_request = requests.get(url)
root = etree.fromstring(url_request.text)
itemid = root.xpath('//main/@id')
description = root.xpath('//main/text()')
xmlitem = root.xpath('//ns:XmlItem', namespaces={'ns': 'http://fakenamespace.com'})
# return render_template('create-definitions.html', itemid=itemid, name=name, description=description, xmlitem=xmlitem)
return render_template('create-definitions.html', **locals())
TEXTAREA NEEDING THE XML:
<textarea rows="20" name="xmlitem" id="xmlitem" >{{ request.args.get('xmlitem') }}</textarea>
Thanks,
Zach
The information contained in this communication is intended for the use
of the designated recipients named above. If the reader of this
communication is not the intended recipient, you are hereby notified
that you have received this communication in error, and that any review,
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please
notify The Associated Press immediately by telephone at +1-212-621-1898
and delete this email. Thank you.
[IP_US_DISC]
msk dccc60c6d2c3a6438f0cf467d9a4938
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20151202/06cb100d/attachment.html>
More information about the Flask
mailing list