I am trying to access a url from flutter webview , however, I am getting the following error. When I try to access this directly, I dont see any error.
File "/home/quiz/views.py", line 629, in dispatch
return super(QuizTakeAutoAuth, self).dispatch(request, *args, **kwargs)
TypeError: get() got an unexpected keyword argument 'quiz_name'
views.py
class QuizTakeAutoAuth(APIView):
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'foo': 'bar'
}
return Response(content)
def dispatch(self, request, *args, **kwargs):
self.quiz = get_object_or_404(Quiz, url=self.kwargs['quiz_name'])
if self.quiz.draft and not request.user.has_perm('quiz.change_quiz'):
raise PermissionDenied
if self.sitting is False:
print("sitting false")
if self.logged_in_user:
return render(request, self.single_complete_template_name)
else:
redirecturl = "/login/?next=/quiz/"+self.kwargs['quiz_name']+"/startquiz/"
return redirect(redirecturl)
return super(QuizTakeAutoAuth, self).dispatch(request, *args, **kwargs)
urls.py
url(r'^(?P<quiz_name>[\w-]+)/startquiz/$',view=QuizTakeAutoAuth.as_view(), name='quiz_question_auth'),
What am I missing here? I am using the same view elsewhere without any knox Tokenauthentication and works as expected.
Since you're using a paramater
quiz_name
in the url
, it is being passed to your corresponding view. The current signature of your get
method doesn't accept any additional parameters.
You may fix this by changing the method signature to:
def get(self, request, *args, **kwargs):
quiz_name = kwargs.get('quiz_name')
...