4

我已经编写了这个简单的方法,它在终端中似乎运行良好,但是每次我在浏览器中启动它时,我都会得到:'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:

<body>
        <div class="wrap">
            <div class="banner">Infobesity</div>

            <!-- Subscriptions -->
                <div class="subscriptionsDiv">
                    <ol class="subscriptionsList">
                    {% for subscription in subscriptions_list %}
                        <li>{{ subscription }}</li>
                    {% endfor %}
                    </ol>
                </div>
            <!-- Subscriptions End -->

            <!--  Items -->
                <div class="itemsDiv">
                    <ol class="itemsList">
                    {% for item in items_list %}
                        <li>{{ item }}</li>
                    {% endfor %}
                    </ol>
                </div>

            <!-- Items End -->
        </div>
    </body>

追溯:

   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():
4

1 回答 1

10

HttpResponse你不打电话就回来;这是一个类,因此不可迭代。

也许您打算在回复中返回html

return HttpResponse(html)
于 2013-01-12T10:11:33.853 回答