3

I get this error

TypeError at /debate/1/
get_context_data() takes exactly 2 arguments (1 given)

Right now it is defined as:

 def get_context_data(self, **kwargs):

And I want it to be:

 def get_context_data(self, request, **kwargs):

so I can do inside:

sort_by = request.GET.get('sort', '-rating_score')

Is this a good idea, and how to do it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tamara
  • 120
  • 1
  • 12

1 Answers1

6

Request object is available as member of a Class Based View object and can be accessed by self.request. If, for some reason, you do pass it in **kwargs use kwargs.get("request") since it's a plain dict.

Davor Lucic
  • 28,970
  • 8
  • 66
  • 76