Django-方法的签名与类中基本方法的签名不匹配 [英] Django - Signature of method does not match signature of base method in class
问题描述
我正在学习Django,并且正在学习lynda.com课程.在其中的一门课程建设电子学习站点"中,具有以下代码:
I am learning Django and I am following a lynda.com course. In one of there courses "building an elearning site", the have the following code:
class CourseModuleUpdateView(TemplateResponseMixin, View):
template_name = 'courses/manage/module/formset.html'
course = None
def get_formset(self, data=None):
return ModuleFormSet(instance=self.course,
data=data)
def dispatch(self, request, pk):
self.course = get_object_or_404(Course, id=pk, owner=request.user)
return super(CourseModuleUpdateView, self).dispatch(request, pk)
def get(self, request, *args, **kwargs):
formset = self.get_formset()
return self.render_to_response({'course': self.course,
'formset': formset})
def post(self, request, *args, **kwargs):
formset = self.get_formset(data=request.POST)
if formset.is_valid():
formset.save()
return redirect('manage_course_list')
return self.render_to_response({'course': self.course,
'formset': formset})
但是我从以下位置收到来自PyCharm(我的IDE)的错误消息:
But I am getting an error message from PyCharm (my IDE) on:
def dispatch(self, request, pk):
错误是:
Signature of method 'CourseModuleUpdateView.dispatch()' does not match signature of base method in class 'View' less... (Ctrl+F1)
This inspection detects inconsistencies in overriding method signatures.
我是否可以解决此问题并查看如何开始解决错误?Pycharm甚至想告诉我什么?
Is there a way for me to troubleshoot the issue and see how to begin fixing the error? What is Pycharm even trying to tell me??
我正在使用python 3和DJango 1.11
I am using python 3 and DJango 1.11
推荐答案
您正在覆盖签名为 def的父类
与您看到的不匹配. View
的方法 dispatch
dispatch(self,request,* args,** kwargs):
You're overriding a method dispatch
of the parent class View
whose signature is def dispatch(self, request, *args, **kwargs):
which you can see from yours does not match.
这里的签名意味着方法参数应与您要覆盖的父类方法匹配.
Signature here means that the method arguments should match with parent class method you're overriding.
这篇关于Django-方法的签名与类中基本方法的签名不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!