简体   繁体   English

在Django的RSS feed中添加Favicon

[英]Add Favicon in RSS feeds in Django

I have used RSS Feed with django, 我已经将RSS Feed与django一起使用了,

I have refer the below link https://docs.djangoproject.com/en/dev/ref/contrib/syndication/ 我已经参考了以下链接https://docs.djangoproject.com/en/dev/ref/contrib/syndication/

And properly created the RSS, but Now I want to add the favicon for the RSS feeds pages. 并正确创建了RSS,但是现在我想为RSS feed页面添加图标。

Can anybody suggest me? 有人可以建议我吗?

Thanks. 谢谢。

My code is: 我的代码是:

In feeds/feed.py 在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

In urls.py 在urls.py中

(r'^feeds/article/$', LatestArticlesFeed()),

Add this to your urls.py file: 将此添加到您的urls.py文件中:

(r'^favicon\.ico$', 
 'django.views.generic.simple.redirect_to', 
 {'url': '/media/favicon.ico'}),

If you're talking about a WebFaction Django install, you should be able to edit the .conf file in the apache2 directory in your app's directory and add a Redirect /favicon.ico http://example.com/static/favicon.ico 如果您要谈论的是WebFaction Django安装,则应该能够在应用程序目录的apache2目录中编辑.conf文件,并添加重定向/favicon.ico http://example.com/static/favicon.ico

Note that you can also specify a favicon in the HTML: 请注意,您还可以在HTML中指定一个图标:

<link rel="shortcut icon" href="http://example.com/myicon.ico" />

As of Django 1.5 simple views like from Plymorphin's answer don't exist anymore. 从Django 1.5开始,像Plymorphin的答案这样的简单视图不再存在。 Modern approach to do this is presented below. 下面介绍了实现此目的的现代方法。

Assuming you have your favicon with other static files at: your_app/static/favicon.ico you can add to main urls.py: 假设您的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'))),
)

or extend existing patterns inline. 或内联扩展现有模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM