Skip to content

Commit 81d3d56

Browse files
authored
Feat: validate district URL and add 404 handler (#102)
2 parents 6e5bc91 + 7fb0979 commit 81d3d56

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

pems/districts/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
URLConf for the districts app.
33
"""
44

5-
from django.urls import path
5+
from django.urls import path, re_path
66

77
from pems.districts import views
88

99
app_name = "districts"
1010
urlpatterns = [
1111
# /districts
1212
path("", views.IndexView.as_view(), name="index"),
13-
path("<int:district_number>", views.DistrictView.as_view(), name="district"),
13+
re_path(r"^(?P<district_number>([1-9]|1[0-2]))$", views.DistrictView.as_view(), name="district"),
1414
]

pems/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _filter_empty(ls):
5252
TEMPLATES = [
5353
{
5454
"BACKEND": "django.template.backends.django.DjangoTemplates",
55-
"DIRS": [],
55+
"DIRS": [os.path.join(BASE_DIR, "pems", "templates")],
5656
"APP_DIRS": True,
5757
"OPTIONS": {
5858
"context_processors": [

pems/templates/404.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "core/base.html" %}
2+
{% block headline %}
3+
Sorry! We can’t find that page.
4+
{% endblock headline %}
5+
{% block inner-content %}
6+
<p>The page you are looking for might be somewhere else or may not exist anymore.</p>
7+
{% endblock inner-content %}

0 commit comments

Comments
 (0)