catch wrong post id

This commit is contained in:
2021-05-13 18:24:25 +00:00
parent bc7da49597
commit 1ae6ecddae

View File

@@ -3,7 +3,7 @@ import logging
from collections import deque
from django.conf import settings
from django.contrib import messages
from django.http import HttpResponse, JsonResponse, HttpResponseServerError
from django.http import HttpResponse, JsonResponse, HttpResponseServerError, Http404
from django.shortcuts import render
from django.template.loader import render_to_string
from django.utils import timezone
@@ -115,13 +115,18 @@ def tags(request, tag=""):
def __get_post_object(id=None):
post = None
try:
if id.isdigit() or id is int:
return Post.objects.get(id=int(id))
post = Post.objects.get(id=int(id))
elif id != "" and id is not None:
return Post.objects.get(slug=id)
return None
post = Post.objects.get(slug=id)
except Exception:
logger.info("Wrong id '{}'".format(id))
raise Http404("wrong post id")
return post
def show(request, id=None):
p = __get_post_object(id)