From 9876bfc168751a6ad3ccec785ca11ef9748905f5 Mon Sep 17 00:00:00 2001 From: Luis Alvergue Date: Thu, 17 Apr 2025 20:37:40 +0000 Subject: [PATCH 1/2] feat: validate district number in district URL pattern validate the URL pattern to only allow 1-12 for district number --- pems/districts/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pems/districts/urls.py b/pems/districts/urls.py index a56d963..979bf94 100644 --- a/pems/districts/urls.py +++ b/pems/districts/urls.py @@ -2,7 +2,7 @@ URLConf for the districts app. """ -from django.urls import path +from django.urls import path, re_path from pems.districts import views @@ -10,5 +10,5 @@ urlpatterns = [ # /districts path("", views.IndexView.as_view(), name="index"), - path("", views.DistrictView.as_view(), name="district"), + re_path(r"^(?P([1-9]|1[0-2]))$", views.DistrictView.as_view(), name="district"), ] From 7fb0979a24297fb2c91aa8f87f8a527e4a9a10d4 Mon Sep 17 00:00:00 2001 From: Luis Alvergue Date: Fri, 2 May 2025 13:04:01 +0000 Subject: [PATCH 2/2] feat: implement a page not found (404) error template --- pems/settings.py | 2 +- pems/templates/404.html | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 pems/templates/404.html diff --git a/pems/settings.py b/pems/settings.py index 329d965..4d776a4 100644 --- a/pems/settings.py +++ b/pems/settings.py @@ -52,7 +52,7 @@ def _filter_empty(ls): TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], + "DIRS": [os.path.join(BASE_DIR, "pems", "templates")], "APP_DIRS": True, "OPTIONS": { "context_processors": [ diff --git a/pems/templates/404.html b/pems/templates/404.html new file mode 100644 index 0000000..c0944fd --- /dev/null +++ b/pems/templates/404.html @@ -0,0 +1,7 @@ +{% extends "core/base.html" %} +{% block headline %} + Sorry! We can’t find that page. +{% endblock headline %} +{% block inner-content %} +

The page you are looking for might be somewhere else or may not exist anymore.

+{% endblock inner-content %}