【发布时间】:2014-07-06 15:54:16
【问题描述】:
我有新闻标题和网址。如何进入链接?
这就是我提取标题和网址的方式:
def Save(request):
news = []
links = []
url ="http://www.basketnews.lt/lygos/59-nacionaline-krepsinio-asociacija/2013/naujienos.html"
r = requests.get(url)
soup = BeautifulSoup(r.content)
nba = soup.select('div.title > a')
for i in reversed(nba):
news.append(i.text) # Here I have list of titles
links.append(i["href"]) # list of urls
# Here I'm saving that info to my model. Ignore it
save_it = Naujienos(title = i.text, url = "Basketnews.lt" + i['href']) #
save_it.save()
return render(request, 'Titles.html', {'news': news, "links": links})
这是我的 HTML:
{% for i in news%}
{% for o in links%}
<a href={{o}}>{{i}}</a>
{% endfor %}
{% endfor %}
我想你已经知道这种制作链接已经过时了。那么,正确的做法是什么?
【问题讨论】:
-
它不起作用吗?有什么错误? {{ i }} 应该可以工作
-
另外,render 方法好像必须要去掉...
标签: python django python-2.7