Skip to content

Commit

Permalink
Add custom 404 and summoner not found page.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjp93 committed Aug 10, 2024
1 parent a43a3d0 commit e2c3a34
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lolsite/settings_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]
BASE_URL = "http://localhost:3000"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
] + MIDDLEWARE

if 'test' not in sys.argv:
if 'test' not in sys.argv and DEBUG:
INSTALLED_APPS += [
"debug_toolbar",
]
Expand Down Expand Up @@ -72,7 +72,7 @@
CORS_ALLOWED_ORIGINS = ['http://localhost:3000']

def show_toolbar(request):
return True
return DEBUG

DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK" : show_toolbar,
Expand Down
9 changes: 7 additions & 2 deletions player/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from functools import cached_property
import urllib.parse

from django.shortcuts import redirect
from django.http import Http404
from django.shortcuts import redirect, render
from django.contrib.auth import authenticate, login, logout
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils import timezone
from django.views import generic
Expand Down Expand Up @@ -147,7 +149,10 @@ def get(self, request, *args, **kwargs):
else:
name = search
tagline = f"{region}1"
summoner = MatchBySummoner.get_summoner(name, tagline, region)
try:
summoner = MatchBySummoner.get_summoner(name, tagline, region)
except Http404:
return render(request, 'player/summoner_not_found.html')
name, tagline = summoner.simple_riot_id.split("#")
return redirect(
"player:summoner-page",
Expand Down
10 changes: 10 additions & 0 deletions templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'layout/base.html' %}

{% block content %}
<div class="container mx-auto">
<h1>Error 404</h1>
<div>
Sorry, we couldn't find what you're looking for.
</div>
</div>
{% endblock content %}
9 changes: 9 additions & 0 deletions templates/player/summoner_not_found.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'layout/base.html' %}
{% block content %}
<div class="container mx-auto">
<h1>Summoner Not Found</h1>
<div>
Sorry, the summoner you searched for could not be found.
</div>
</div>
{% endblock content %}

0 comments on commit e2c3a34

Please sign in to comment.