Skip to content

Commit ece9364

Browse files
authored
Merge pull request #18 from SADiLaR/feature/error_pages
Error pages
2 parents 891f1e3 + 98c382d commit ece9364

File tree

8 files changed

+102
-0
lines changed

8 files changed

+102
-0
lines changed

app/app/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@
2929
path("", views.home, name="home"),
3030
path("institutions/", views.institutions, name="institutions"),
3131
]
32+
33+
handler400 = "app.views.error_400"
34+
handler403 = "app.views.error_403"
35+
handler404 = "app.views.error_404"
36+
handler500 = "app.views.error_500"

app/app/views.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,31 @@ def institutions(request):
2525
context = {"institutions_page": "active", "institutions": institutions}
2626

2727
return render(request, template_name=template, context=context)
28+
29+
30+
def error_400(request, exception):
31+
template = "400.html"
32+
context = {}
33+
34+
return render(request, template_name=template, context=context)
35+
36+
37+
def error_403(request, exception):
38+
template = "403.html"
39+
context = {}
40+
41+
return render(request, template_name=template, context=context)
42+
43+
44+
def error_404(request, exception):
45+
template = "404.html"
46+
context = {}
47+
48+
return render(request, template_name=template, context=context)
49+
50+
51+
def error_500(request):
52+
template = "500.html"
53+
context = {}
54+
55+
return render(request, template_name=template, context=context)

app/static/css/styles.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ body {
137137
margin: 10px 0 0 0;
138138
}
139139

140+
/*Error pages*/
141+
.error-card {
142+
border-color: var(--primary-red);
143+
margin: 0 10px 0 10px;
144+
width: 100%;
145+
}
146+
140147
/*bootstrap icons*/
141148
.bi {
142149
font-size: 50px;

app/templates/400.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "base_error.html" %}
2+
3+
{% block error_content %}
4+
5+
<div class="card-body">
6+
<h5 class="card-title">Bad Request (400)</h5>
7+
<p class="card-text">The server cannot process the request due to client error.</p>
8+
<a href="{% url 'home' %}" class="btn btn-primary">Go to home</a>
9+
</div>
10+
11+
{% endblock error_content %}

app/templates/403.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "base_error.html" %}
2+
3+
{% block error_content %}
4+
5+
<div class="card-body">
6+
<h5 class="card-title">Forbidden (403)</h5>
7+
<p class="card-text">You do not have permission to access on this server.</p>
8+
<a href="{% url 'home' %}" class="btn btn-primary">Go to home</a>
9+
</div>
10+
11+
{% endblock error_content %}

app/templates/404.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "base_error.html" %}
2+
3+
{% block error_content %}
4+
5+
<div class="card-body">
6+
<h5 class="card-title">Not Found (404)</h5>
7+
<p class="card-text">The requested resource was not found on this server.</p>
8+
<a href="{% url 'home' %}" class="btn btn-primary">Go to home</a>
9+
</div>
10+
11+
{% endblock error_content %}

app/templates/500.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "base_error.html" %}
2+
3+
{% block error_content %}
4+
5+
<div class="card-body">
6+
<h5 class="card-title">Internal Server Error (500)</h5>
7+
<p class="card-text">The server encountered an unexpected condition that prevented it from fulfilling the request.</p>
8+
<a href="{% url 'home' %}" class="btn btn-primary">Go to home</a>
9+
</div>
10+
11+
{% endblock error_content %}

app/templates/base_error.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
<div class="section mt-3 mb-3">
6+
<div class="card text-center error-card">
7+
<div class="card-header">
8+
Error
9+
</div>
10+
<div id="error_content">
11+
{% block error_content %}
12+
13+
{% endblock error_content %}
14+
</div>
15+
</div>
16+
</div>
17+
18+
{% endblock content %}

0 commit comments

Comments
 (0)