Django - Signature of method does not match signature of base method in class

Firstly you have to understand that this is a warning, not error.

Secondly: every argument (except of request) that is passed to view by Django is extracted from URL, as defined in urlpatterns. Django is using *args and **kwargs internally in class-based views so you can pass any argument without need for overwriting dispatch method.

And back to our warning: this warning is raised by many of static code analysis tools (including one built into PyCharm) to inform you that something here may be wrong, because original dispatch method has different signature. It doesn't mean that this is wrong and that's why there are always options to mute those warnings on selected code lines. You should of course look at every warning your editor raises, but that doesn't mean that every warning should be fixed.

You can fix it of course using:

    def dispatch(self, request, *args, **kwargs):
        id = args[0] # or id = kwargs['id'] if it is passed as keyword argument
        self.course = get_object_or_404(Course, id=pk, owner=request.user)
        return super(CourseModuleUpdateView, self).dispatch(request, pk)

but you can also ignore that and use as is. Your usage has some benefits, for example automatic validation on method invoke that all required arguments have been passed. Usage with default method signature (as above) has benefit in not raising that warning in your editor. It is up to you to decide which one is better.


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.

Tags:

Python

Django