Hello to all! I want to switch from FBV to CBV, but I don’t understand how to correctly pass parameters to the class. For example in fbv I did this:

url(r'^(?P<user_id>\d+)/main', views.Man, name='man'), 

and in the presentation:

 def Man(request, user_id): 

And then I can use user_id for my needs. How to do the same on cbv? Something searching is tight on this topic

    1 answer 1

    The request object in CVB methods can be obtained from the attribute of the same name - self.request , positional arguments from the self.args list, and named from the self.kwargs dictionary:

     class ManView(DetailView): def get_object(self, queryset=None): request = self.request user_id = self.kwargs.get('user_id') ...