3

Is 1 or 2 the correct way to call a function within a view function in Django. Or are both equally ok. Please explain.

#1
def function1(request):
    [some api calls] 
    #Once this process is done I want to call my second function
    return function2()

def function2():
    # some hard work
    return HttpResponse(...)
#2
def function1(request):
    [some api calls] 
    #Once this process is done I want to call my second function
    function2()

def function2():
    # some hard work
    return HttpResponse(...)
0

2 Answers 2

3

The top one (#1) is the one you want.

#2 just returns the HTTP response to the original function. It returns None to the view itself. It doesn't work and returns this error.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

It depends on what you actually want to do with the return value of function2(). If you want to return this value from function1() , you have to use method 1, because in method 2, function1() just calls function2() , it doesn't return the value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.