48👍
✅
I’d use xmltodict
to make a python dictionary out of the XML
data structure and pass this dictionary to the template inside the context:
import urllib2
import xmltodict
def homepage(request):
file = urllib2.urlopen('https://www.goodreads.com/review/list/20990068.xml?key=nGvCqaQ6tn9w4HNpW8kquw&v=2&shelf=toread')
data = file.read()
file.close()
data = xmltodict.parse(data)
return render_to_response('my_template.html', {'data': data})
12👍
xmltodict
using urllib3
import traceback
import urllib3
import xmltodict
def getxml():
url = "https://yoursite/your.xml"
http = urllib3.PoolManager()
response = http.request('GET', url)
try:
data = xmltodict.parse(response.data)
except:
print("Failed to parse xml from response (%s)" % traceback.format_exc())
return data
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-AngularJS with Django – Conflicting template tags
- [Django]-Remove pk field from django serialized objects
12👍
xmltodict
using requests
import requests
import xmltodict
url = "https://yoursite/your.xml"
response = requests.get(url)
data = xmltodict.parse(response.content)
- [Django]-How to query abstract-class-based objects in Django?
- [Django]-Can you migrate backwards to before the first migration in South?
- [Django]-How do I see stdout when running Django tests?
Source:stackexchange.com