Answer the question
In order to leave comments, you need to log in
Django, how to access parameter from url from class?
Hello, do you have a url?
path('api/list_projects/<int:user_id>', ProjectsView.as_view())
class ProjectsView(View):
def get(self):
user = self.kwargs["user_id"]
user_account = UserAccount.objects.get(user=user)
customer = Customer.objects.get(useraccount=user_account)
projects = Project.objects.filter(customer=customer)
return JsonResponse(projects, safe=False)
Answer the question
In order to leave comments, you need to log in
class ProjectsView(View):
def get(self, request, *args, **kwargs):
user = kwargs["user_id"]
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question