From cdc03af8d6a27acb00bbbed68a6a871540e469e3 Mon Sep 17 00:00:00 2001 From: liangliangyy Date: Tue, 28 Mar 2023 15:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comments/views.py | 8 ++++---- requirements.txt | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) 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 63fde31..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,17 +11,17 @@ 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 -redis==4.5.1 +redis==4.5.3