'how to redirect from a function to a url using name attribute + "?next=next_path" in django redirect?

view.py

def register(request):
    next_cart_page = request.GET.get('next', '')
    if request.method == 'POST':
        status =  logic.register_logic(request)
        if next_cart_page == 'cart':
            return redirect("/u/o/?next="+ next_cart_page) <- instead of "/u/o/" how can i use "verify_otp_user"
        else:
            return redirect("verify_otp_user")

main.js

$('.checkout_login_required').click(function(){
    $('#register_user_link').attr('href', function(i, val){
        return val + '?next=cart'
    })
 });

using javascript i'm passing a value to the next key to an anchor tag. then on views.py i'm checking for that value in an if statement and based on that i'm redirecting to the next page with or without the next value

in else statement i'm using path name attribute to redirect to a url how can i do the same in if statement as well while concatinating path name attribute(like verify_otp_user) with "?next=" + next_cart_page something like redirect("verify_otp_user" + "?next=" + next_cart_page), but this is not working . Any alternate solution if available ?

Note: verify_otp_user does not have any parameter in its url its simply /u/o/



Solution 1:[1]

This way:

return redirect('verify_otp_user', next=next_cart_page)

Docs (second example).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yevgeniy Kosmak