[Django]-Django the request argument must be an instance of django.http.HttpRequest

3πŸ‘

βœ…

The reason this fails is because you have two functions that have the same name, so it will call the update_label that you defined in the name.

You can fix this by importing the function with a different name, so:

from custom_label.services.custom_label_svc import update_label as update_label_logic

@api_view(['POST'])
@authorize
def update_label(request) -> JsonResponse:
    try:
        payload = ValidateUpdateLabel(data=request.data)
        if payload.is_valid():
            # call service methods
            data = update_label_logic(payload.validated_data)
    # …

But wrapping the entire logic in a try–except is usually not a good idea. Furhtermore your function is vulnerable to SQL injection.

Leave a comment