簡體   English   中英

在Django的RSS feed中添加Favicon

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM