catch wrong post id
This commit is contained in:
@@ -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):
|
||||
if id.isdigit() or id is int:
|
||||
return Post.objects.get(id=int(id))
|
||||
elif id != "" and id is not None:
|
||||
return Post.objects.get(slug=id)
|
||||
post = None
|
||||
|
||||
return None
|
||||
try:
|
||||
if id.isdigit() or id is int:
|
||||
post = Post.objects.get(id=int(id))
|
||||
elif id != "" and id is not 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)
|
||||
|
||||
Reference in New Issue
Block a user