Not getting any output in Django for BeautifulSoup
<p>I am trying BeautifulSoup4 in Django and I parsed an XML page with it. When I try the parsing the same XML page in a python interpreter in a different way, it works fine. But in Django, I get a page as shown below.</p>

<p><a href="http://i.stack.imgur.com/hPWuk.png" rel="nofollow"><img src="http://i.stack.imgur.com/hPWuk.png" alt="enter image description here"></a></p>

<p>views.py:</p>

<pre><code>def rssfeed(request):
    list1=[]
    xmllink="https://rss.sciencedaily.com/computers_math/computer_programming.xml"
    soup=BeautifulSoup(urlopen(xmllink),'xml')
    for items in soup.find_all('item'):
        list1.append(items.title)
    context={
        "list1":list1
    }
    return render(request,'poll/rssfeed.html',context)
</code></pre>

<p>rssfeed.html:</p>

<pre><code>{% if list1 %}

&lt;ul&gt;
    {% for item in list1 %}
        &lt;li&gt;{{ item }}&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
{% endif %}
</code></pre>

<p>What is that I am doing wrong?</p>

<p>From <a href="https://docs.djangoproject.com/en/1.10/ref/templates/api/#variables-and-lookups" rel="nofollow">documentation</a></p>

<blockquote>
  <p>If any part of the variable is callable, the template system will try calling it.</p>
</blockquote>

<p>and</p>

<blockquote>
  <p>Occasionally you may want to turn off this feature for other reasons, and tell the template system to leave a variable uncalled no matter what. To do so, set a do_not_call_in_templates attribute on the callable with the value True. </p>
</blockquote>

<p>And from <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#calling-a-tag-is-like-calling-find-all" rel="nofollow">BeautifulSoup documentation</a></p>

<blockquote>
  <p>Calling a tag is like calling find_all()</p>
</blockquote>

<p>Eg. <code>tagX('a')</code> returns a list of all the <code>&lt;a&gt;</code> tags found within this <code>tagX</code>.</p>

<p>The <code>item</code> in your template refers to instance of <code>bs4.element.Tag</code>, which is callable. So Django is calling the <code>item</code> variable with zero arguments, which means it will return list of all the elements inside <code>item</code>, which is none as it contains only text. Hence the blank lists.</p>

<p>So either parse the context before passing it to the template</p>

<pre><code>list1 = [item.title.text for item in soup.find_all('item')]
</code></pre>

<p>Or if you want to pass the instance for some reason, you can set the <code>do_not_call_in_templates</code> attribute to to</p>

<pre><code>for item in soup.find_all('item'):
    title = item.title
    title.do_not_call_in_templates = True
    list1.append(title)
</code></pre>

python django beautifulsoup render