S
S
Sergey Alekseev2018-03-30 10:45:12
Django
Sergey Alekseev, 2018-03-30 10:45:12

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())

views
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)

I do not understand how to do it from the class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-03-30
@serj2000

class ProjectsView(View):
    def get(self, request, *args, **kwargs):
        user = kwargs["user_id"]
       ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question