From 297b95a3a87a1c6356d6a25c44a62ec0c5bc3d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Helle=C5=9Ben?= Date: Thu, 26 Mar 2026 19:25:53 +0100 Subject: [PATCH] Use templates --- feeds/urls.py | 3 ++- feeds/views.py | 28 ++++++++++++++++----------- templates/base.html | 35 ++++++++++++++++++++++++++++++++++ templates/feeds/feed_list.html | 11 +++++++++++ 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 templates/base.html create mode 100644 templates/feeds/feed_list.html diff --git a/feeds/urls.py b/feeds/urls.py index 60725e9..163c7f0 100644 --- a/feeds/urls.py +++ b/feeds/urls.py @@ -10,7 +10,8 @@ if TYPE_CHECKING: urlpatterns: list[URLPattern | URLResolver] = [ - path("", views.feed_list, name="feed-list"), + path("", views.home, name="home"), + path("feeds/", views.feed_list, name="feed-list"), path("feeds//", views.feed_detail, name="feed-detail"), path( "feeds//entries//", diff --git a/feeds/views.py b/feeds/views.py index ab79681..5780b22 100644 --- a/feeds/views.py +++ b/feeds/views.py @@ -1,9 +1,13 @@ +from __future__ import annotations + import html import json from typing import TYPE_CHECKING from django.http import HttpResponse from django.shortcuts import get_object_or_404 +from django.shortcuts import redirect +from django.shortcuts import render from feeds.models import Entry from feeds.models import Feed @@ -20,17 +24,7 @@ def feed_list(request: HttpRequest) -> HttpResponse: HttpResponse: An HTML response containing the list of feeds. """ feeds = Feed.objects.all().order_by("id") - html = [ - "", - "FeedVault - Feeds", - "

Feed List

", - "
    ", - ] - html.extend( - f'
  • {feed.url}
  • ' for feed in feeds - ) - html.extend(("
", "")) - return HttpResponse("\n".join(html)) + return render(request, "feeds/feed_list.html", {"feeds": feeds}) def feed_detail(request: HttpRequest, feed_id: int) -> HttpResponse: @@ -115,3 +109,15 @@ def entry_detail(request: HttpRequest, feed_id: int, entry_id: int) -> HttpRespo "", ] return HttpResponse("\n".join(html_lines)) + + +def home(request: HttpRequest) -> HttpResponse: + """Redirect to the feed list as the homepage. + + Args: + request: The HTTP request object. + + Returns: + HttpResponse: A redirect response to the feed list. + """ + return redirect("/feeds/") diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..ae5836d --- /dev/null +++ b/templates/base.html @@ -0,0 +1,35 @@ + + + + + + + + {% block title %} + FeedVault + {% endblock title %} + + + +
+

FeedVault

+ +
+
+ {% block content %} + {% endblock content %} +
+
+

Web scraping is not a crime. - No rights reserved. - A birthday present for Plipp ❤️

+
+ + diff --git a/templates/feeds/feed_list.html b/templates/feeds/feed_list.html new file mode 100644 index 0000000..d6c9e55 --- /dev/null +++ b/templates/feeds/feed_list.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block content %} +

Feed List

+ +{% endblock content %}