RSS support

This commit is contained in:
MatthiasSaihttam 2020-09-12 13:04:34 -04:00
parent 1fc2fcbd7e
commit 89fa8efd87
4 changed files with 29 additions and 1 deletions

24
main/feed.py Normal file
View File

@ -0,0 +1,24 @@
from django.contrib.syndication.views import Feed
from main.models import Thought
class MainFeed(Feed):
title = "Thoughts"
link = "/"
@staticmethod
def items():
return Thought.objects.all().order_by("-posted")
def item_title(self, item):
return item.text
def item_description(self, item):
return item.extended_text
def item_link(self, item):
return "/"
def item_pubdate(self, item):
return item.posted

View File

@ -162,4 +162,4 @@ footer {
width: 100%;
padding: 10px;
height: 20px;
}
}

View File

@ -10,6 +10,8 @@
<link rel="icon" sizes="192x192" href="{% static 'images/favicon-192x192.png'%}">
<link rel="apple-touch-icon" href="{% static 'images/apple-touch-icon.png'%}"/>
<link rel="alternate" href="/feed" type="application/rss+xml" title="RSS">
</head>
<body>
<header><span class="text">Thoughts</span>{% if authenticated %}

View File

@ -16,8 +16,10 @@ Including another URLconf
from django.urls import path
from main import views
from main.feed import MainFeed
urlpatterns = [
path("", views.index, name="index"),
path("post", views.post, name="post"),
path("feed", MainFeed())
]