RSS feed?

360 views
Skip to first unread message

Paul

unread,
Jun 20, 2018, 3:10:17 PM6/20/18
to Mezzanine Users
Howdy.

I'm on Mezzanine 4.2.2 and Django 1.10.4. 

I see some remnants of RSS throughout the code, but I can't seem to get it working.

I assume it needs no other config, it simply works.

I tried adding this to my base.html, per what I found within the Mezzanine base.html file:

    <link rel="alternate" type="application/rss+xml" title="RSS" href="{% url "blog_post_feed" "rss" %}">
    <link rel="alternate" type="application/atom+xml" title="Atom" href="{% url "blog_post_feed" "atom" %}">

However, that didn't work, it's throwing a 404 (when I view source and go to resulting url).

I've tried /feed.xml as well, and that was a 404. 

Does RSS need to be enabled for it to work? Or do I need a template for this? I couldn't find something clear in the docs or on Google.

Thank you. 

Stephen McDonald

unread,
Jun 20, 2018, 3:14:43 PM6/20/18
to Mezzanine Users
It should just work, here it is on the demo site: http://mezzanine.jupo.org/blog/feeds/rss/

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen McDonald
http://jupo.org

Paul Gx

unread,
Jun 20, 2018, 3:31:04 PM6/20/18
to mezzani...@googlegroups.com
Thank you Stephen for the quick response.

I believe I found the conflict, I have this in urls.py:

url(r'^articles/(?P<slug>[^/]*)/.+$', views.article_redirect, name='Articles'),

If I comment out this line it does work.

Is there a way in urls.py to have articles/feeds/ ignored? 

Or, in views.article_redirect, I could run some logic if slug == 'feeds'. 

Thanks!

Stephen McDonald

unread,
Jun 20, 2018, 3:37:59 PM6/20/18
to Mezzanine Users
If you read the Django docs you'l learn that the order of the urlpatterns matters:



Paul Gx

unread,
Jun 20, 2018, 3:44:15 PM6/20/18
to mezzani...@googlegroups.com
Yes, thank you.

I tried to import core in urls to put rss feed above mine:

from mezzanine.blog import mezzanine_views
_slash = "/" if settings.APPEND_SLASH else ""

...
    url(r"^articles/feeds/(?P<format>.*)%s$" % _slash,
        mezzanine_views.blog_post_feed, name="blog_post_feed"),
    url(r'^articles/(?P<slug>[^/]*)/.+$', views.articles_redirect, name='Insight'),

And articles_redirect() is...

def articles_redirect(request, slug):
    return HttpResponsePermanentRedirect(reverse('blog_post_detail', kwargs={'slug': slug}))

I did this a while back, not sure how this helps me (I suspect it would be redundant but I must have had a reason for it, it was in my earlier days with Mezzanine and Django)

Paul Gx

unread,
Jun 20, 2018, 3:48:13 PM6/20/18
to mezzani...@googlegroups.com
Ah! I remember now. In our old system, we had unique codes at the end of blog articles. 

eg. /article/some-title-slug/sdf23

This is the only way I knew how to set up that redirect so it works properly. 

Paul Gx

unread,
Jun 20, 2018, 5:12:01 PM6/20/18
to mezzani...@googlegroups.com
Ok, got it, I added this in views:

def feed(request, format, **kwargs):
    """
    Blog posts feeds - maps format to the correct feed view.
    """
    try:
        return {"rss": PostsRSS, "atom": PostsAtom}[format](**kwargs)(request)
    except KeyError:
        raise Http404()

Modified this in urls:

    url(r'^articles/feeds/(?P<format>[^/]*)/$', views.feed, name='Articles Feed'),
    url(r'^ articles/(?P<slug>[^/]*)/.+$', views.article_redirect, name='Articles'),

I took feed() from core, seems to do the trick.

Thanks – 
Reply all
Reply to author
Forward
0 new messages