【发布时间】:2011-07-08 02:37:39
【问题描述】:
您好,我得到了以下过滤器,该过滤器与 django 0.96 (GAE) 一起使用,并在使用 GAE + django 1.2 时生成错误的布局代码。现在我想更新过滤器,使其适用于 django 1.2。您能否提供任何信息,请提供。
过滤器:
def news(n):
url = os.environ.get('HTTP_HOST') if os.environ.get('HTTP_HOST') else os.environ['SERVER_NAME']
tld = url[url.rfind('.'):]
try:
if url == 'localhost:8080' or url.endswith('alltfunkar.com'):
result = urlfetch.fetch('http://news.google.se/?output=rss')
elif tld != '.com' and tld != '.se' and tld != '.cl' :
result = urlfetch.fetch('http://news.google.com'+tld+'/?output=rss')
else:
#result = urlfetch.fetch('http://news.google'+tld+'/?output=rss')
result = urlfetch.fetch('http://news.google.com/?output=rss')
if result.status_code == 200:
dom = minidom.parseString(result.content)
item_node = dom.getElementsByTagName("item")
try:
random_1=random.choice(item_node)
rss1_link = random_1.childNodes[1].firstChild.data
rss1_text = random_1.childNodes[0].firstChild.data
return '<a href="'+rss1_link+'">'+rss1_text+'</a>'
except IndexError,e:
return ''
except urlfetch.Error, e:
pass
register.filter(news)
模板使用
{{a|news|fix_ampersands|truncatewords_html:8}
在此处的帮助下解决并完成!非常感谢:
【问题讨论】:
标签: python django google-app-engine