저는 form_valid 메소드를 재정의하는 UpdateView가 있습니다. 어떤 이유로 '요청'은 재정의 된 메소드 내에서 정의되지 않은 것으로 표시됩니다. 여기에 전체 클래스는 다음과 같습니다글로벌 이름 'request'가 정의되어 있지 않습니다. override form_valid
class UpdateTopic(UpdateView):
model = Post
slug_field = 'pk'
slug_url_kwarg = 'pk'
form_class = CommentForm
template_name = "forums/update_topic.html"
def form_valid(self, form):
user = self.request.user
rep = self.request.user.player.get_rep_total
# protect the system against url input attacks
if user == self.object.user or rep >=2500:
self.object = form.save(commit=False)
self.object.updated_by = self.request.user
self.object.save()
messages.add_message(request, message.SUCCESS, "<strong>Success:</strong> The comment was edited successfully!")
else:
messages.add_message(request, message.ERROR, "<strong>Failed:</strong> You don't have the access level to edit that post!")
문제는 그것은 request
처럼 보인다 messages.add_message(request, message.SUCCESS, "<strong>Success:</strong> The comment was edited successfully!")
이 범위를 벗어난 몇 가지 방법입니다 라인을합니다. 왜이 일을하는거야? 이 문제를 해결할 방법이 있습니까?
'요청'이 아니라 'self.request'여야합니다. –
@limelights 아마도 답변으로 게시 할 수 있습니까? – icedtrees