呈现函数(视图)返回的列表中的项

2024-09-30 05:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有从列表中显示的链接,但它们没有被解析为“可点击”

我的模板如下所示:

 <html>
 <body>
 <h2>All listing</h2> 
 {% for link in name %}
   <div>
     <ul>
    <li> {{ link }}</li>
     </ul>
   </div>
 {% endfor %}
 </body>
 </html>

我希望上面的链接可以点击返回,但是我只看到原始html如下:

<a href="http://www.businessghana.com/portal/jobs/index.php?op=getJobInfo&amp;id=103536">Sales Executives needed urgently in Accra</a>
<a href="http://www.businessghana.com/portal/jobs/index.php?op=getJobInfo&amp;id=120007">Direct Sales Officers</a>
<a href="http://www.businessghana.com/portal/jobs/index.php?op=getJobInfo&amp;id=120010">Fleet Engineer</a>
<a href="http://www.businessghana.com/portal/jobs/index.php?op=getJobInfo&amp;id=119866">Business Development Manager</a>
<a href="http://www.businessghana.com/portal/jobs/index.php?op=getJobInfo&amp;id=119846">Administrative &amp; Accounts Assistant Urgently Needed</a>
<a href="http://www.businessghana.com/portal/jobs/index.php?op=getJobInfo&amp;id=119772">Quality Control Officer</a>

当我使用HttpResponse通过下面的视图显示链接时,我得到了我想要的东西

def businessghana(request):
    site = "http://www.businessghana.com/portal/jobs"
    hdr = {'User-Agent' : 'Mozilla/5.0'}
    req = urllib2.Request(site, headers=hdr)
    jobpass = urllib2.urlopen(req)
    soup = BeautifulSoup(jobpass)
    for tag in soup.find_all('a', href = True):
        tag['href'] = urlparse.urljoin('http://www.businessghana.com/portal/', tag['href'])
    html = map(str, soup.find_all('a', href = re.compile('.getJobInfo')))
    return HttpResponse(html)

但一旦我添加了一个模板,我就再也不会这样了。 我怎样才能让我的链接已经解析为可点击而不是原始的html?你知道吗

提前感谢大家,祝大家节日快乐

最大


Tags: comidhttpindex链接htmlwwwjobs

热门问题