3
In mapping my.py urls I use from common functions to class-based views.
I want to know the difference between calling the view with or without parentheses, given that if I have the input url(r'^$', base_views.index_view)
, place parentheses when calling the corresponding function (which in the declaration receives only one object request) spear one Typeerror with the following message: index_view() Missing 1 required positional argument: 'request'.
Already at the entrance url(r'^authors/$', AuthorViews.AuthorView.as_view)
, when I remove the parentheses it throws the same error quoted above with the message: as_view() takes 1 positional argument but 2 Were Given.
I understand that the problem is that when calling one of the functions, the arguments of it are not supplied as in the statement, but, I do not understand how the function url of Django passes these parameters nor why the parentheses make a difference.
It all makes sense now. Had not connected me that the as_view returned a callable, so that’s why we have to execute it: to receive an object the url function will call and send the parameters to it.
– juniorgarcia