catch wrong post id
This commit is contained in:
@@ -3,7 +3,7 @@ import logging
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
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.shortcuts import render
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@@ -115,13 +115,18 @@ def tags(request, tag=""):
|
|||||||
|
|
||||||
|
|
||||||
def __get_post_object(id=None):
|
def __get_post_object(id=None):
|
||||||
|
post = None
|
||||||
|
|
||||||
|
try:
|
||||||
if id.isdigit() or id is int:
|
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:
|
elif id != "" and id is not None:
|
||||||
return Post.objects.get(slug=id)
|
post = Post.objects.get(slug=id)
|
||||||
|
except Exception:
|
||||||
return None
|
logger.info("Wrong id '{}'".format(id))
|
||||||
|
raise Http404("wrong post id")
|
||||||
|
|
||||||
|
return post
|
||||||
|
|
||||||
def show(request, id=None):
|
def show(request, id=None):
|
||||||
p = __get_post_object(id)
|
p = __get_post_object(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user