Py学习  »  问与答

django写的Rss怎么不大对,帮我看看捏

cumt_ttr • 9 年前 • 3828 次点击  

照着youtube上的 Building a blog in 30 mins with Django (Screencast HD)写的 作者的版本是1.3的,我的是1.6.5的 ================代码如下=====

from django.conf.urls import patterns, include, url
from django.views.generic import ListView,DetailView
from blog.models import Post
from blog.views import tagpage
from django.contrib.syndication.views import Feed

class BlogFeed(Feed):

    title = 'MySite'
    description = 'Some ramblings of mine'
    link = '/blog/feed/'

    def items(self):
        return Post.objects.all().order_by('-created')[:2]

    def item_title(self,item):
        return item.title

    def item_description(self,item):
        return item.body

    def item_link(self,item):
        return u'/blog/%d'% item.id

urlpatterns = patterns('blog.view',

    url(r'^$',ListView.as_view(
                            queryset = Post.objects.all().order_by("-created")[:2],
                            template_name = 'blog.html')),

    url(r'^(?P<pk>\d+)/$',DetailView.as_view(
                        model = Post,template_name = "post.html")),

    url(r'^archives/$',ListView.as_view(
                            queryset = Post.objects.all().order_by("-created"),
                            template_name = 'archives.html')),

    url(r'(?P<tag>\w+)/$',tagpage),
    url(r'^feed/$',BlogFeed()),
)

===================================我的效果 enter image description here

=================================作者做出来的效果 enter image description here

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/607
 
3828 次点击  
文章 [ 3 ]  |  最新文章 9 年前
the5fire
Reply   •   1 楼
the5fire    9 年前

@cumt_ttr 或许你应该看看官方文档:https://docs.djangoproject.com/en/1.6/ref/contrib/syndication/#a-simple-example

cumt_ttr
Reply   •   2 楼
cumt_ttr    9 年前

@the5fire 看了半天也不知道我的问题在那里,不过还是谢谢

the5fire
Reply   •   3 楼
the5fire    9 年前

你可以参考我博客的源码:https://github.com/the5fire/django_selfblog/blob/master/selfblog/feeds.py

博客对应功能是:http://www.the5fire.com/feed