[英]Add Favicon in RSS feeds in Django
我已经将RSS Feed与django一起使用了,
我已经参考了以下链接https://docs.djangoproject.com/en/dev/ref/contrib/syndication/
并正确创建了RSS,但是现在我想为RSS feed页面添加图标。
有人可以建议我吗?
谢谢。
我的代码是:
在feeds / feed.py中
class LatestArticlesFeed(Feed):
title='News -RSS'
link='/' # URI of site
description='Latest Article Entries'
def get_object(self, request):
category_slug = request.GET.get('category_slug')
category = Category.objects.get(slug = category_slug)
def items(self, obj):
article_list = Article.objects.filter(category =obj)[:10]
return article_list
def item_title (self, item):
return item.headline
在urls.py中
(r'^feeds/article/$', LatestArticlesFeed()),
将此添加到您的urls.py文件中:
(r'^favicon\.ico$',
'django.views.generic.simple.redirect_to',
{'url': '/media/favicon.ico'}),
如果您要谈论的是WebFaction Django安装,则应该能够在应用程序目录的apache2目录中编辑.conf文件,并添加重定向/favicon.ico http://example.com/static/favicon.ico
请注意,您还可以在HTML中指定一个图标:
<link rel="shortcut icon" href="http://example.com/myicon.ico" />
从Django 1.5开始,像Plymorphin的答案这样的简单视图不再存在。 下面介绍了实现此目的的现代方法。
假设您的favicon和其他静态文件位于: your_app / static / favicon.ico ,则可以添加到主urls.py中:
from django.contrib.staticfiles.templatetags import staticfiles
from django.views.generic import base
...
urlpatterns += patterns(
'',
url('^favicon\.ico$',
base.RedirectView.as_view(url=staticfiles.static('favicon.ico'))),
)
或内联扩展现有模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.