我已经写了这个简单的方法似乎在终端中工作正常,但每次我在浏览器中启动它时,我得到:类型’type’的参数不可迭代.
def get_main(request):
t = get_template('main.html')
p = urllib2.urlopen("http://www.caltech.edu/news/rss.xml")
x = minidom.parseString(p.read())
titles = x.getElementsByTagName("title")
items_list = []
for title in titles:
items_list.append(str(title.firstChild.nodeValue))
subscriptions_list = ['Caltech']
html = t.render(Context({'subscriptions_list': subscriptions_list, 'items_list': items_list}))
return HttpResponse
HTML:
{% for subscription in subscriptions_list %}
{{ subscription }}{% endfor %}
{% for item in items_list %}
{{ item }}{% endfor %}
追溯:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
189. response = self.apply_response_fixes(request, response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in apply_response_fixes
237. response = func(request, response)
File "/usr/local/lib/python2.7/dist-packages/django/http/utils.py" in fix_location_header
19. if 'Location' in response and request.get_host():