Add 404 support

parent 7a66b23e
from django.shortcuts import render, redirect from django.shortcuts import render, redirect, get_object_or_404
from .models import Url from .models import Url
...@@ -11,13 +11,13 @@ def index(request): ...@@ -11,13 +11,13 @@ def index(request):
return render(request, 'index.html', context) return render(request, 'index.html', context)
def redir(request, url_id): def redir(request, url_id):
u = Url.objects.get(id=url_id) u = get_object_or_404(Url, id=url_id)
u.used += 1 u.used += 1
u.save() u.save()
return redirect(u.target) return redirect(u.target)
def details(request, url_id): def details(request, url_id):
context = { context = {
'url': Url.objects.get(id=url_id) 'url': get_object_or_404(Url, id=url_id)
} }
return render(request, 'details.html', context) return render(request, 'details.html', context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment