diff --git a/comments/views.py b/comments/views.py index ac1cf04..b4cf4ca 100644 --- a/comments/views.py +++ b/comments/views.py @@ -1,6 +1,7 @@ # Create your views here. from django.core.exceptions import ValidationError from django.http import HttpResponseRedirect +from django.shortcuts import get_object_or_404 from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect from django.views.generic.edit import FormView @@ -20,14 +21,13 @@ class CommentPostView(FormView): def get(self, request, *args, **kwargs): article_id = self.kwargs['article_id'] - - article = Article.objects.get(pk=article_id) + article = get_object_or_404(Article, pk=article_id) url = article.get_absolute_url() return HttpResponseRedirect(url + "#comments") def form_invalid(self, form): article_id = self.kwargs['article_id'] - article = Article.objects.get(pk=article_id) + article = get_object_or_404(Article, pk=article_id) return self.render_to_response({ 'form': form, @@ -39,7 +39,7 @@ class CommentPostView(FormView): user = self.request.user article_id = self.kwargs['article_id'] - article = Article.objects.get(pk=article_id) + article = get_object_or_404(Article, pk=article_id) if article.comment_status == 'c' or article.status == 'c': raise ValidationError("该文章评论已关闭.") diff --git a/requirements.txt b/requirements.txt index ce971b8..d424b79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -coverage==7.2.1 +coverage==7.2.2 bleach==6.0.0 Django==4.1.7 django-compressor==4.3.1 @@ -11,16 +11,16 @@ elasticsearch-dsl==7.4.0 gevent==22.10.2 jieba==0.42.1 jsonpickle==3.0.1 -Markdown==3.4.1 +Markdown==3.4.3 mysqlclient==2.1.1 Pillow==9.4.0 Pygments==2.14.0 python-logstash==0.4.8 python-slugify==8.0.1 -pytz==2022.7.1 +pytz==2023.2 raven==6.10.0 requests==2.28.2 -urllib3==1.26.14 +urllib3==1.26.15 WeRoBot==1.13.1 Whoosh==2.7.4 user-agents==2.2.0