Search code examples
djangoget

Get request parameter not triggering if statement in Django


Django newbie.

I'm trying to pass 'id_numb' as a get request, here's the URL: mysite/?id_numb=1. However, it does not make it to the second if statement.

if request.GET['id_numb']:
        id_numb = request.GET['id_numb']
        if id_numb == 1:
            # doesn't make it here - never get to this code, even when 1 is passed
            ....different code
        else:
            ....some code
    else:
        .... some other code

Solution

  • maybe you can try

    if request.GET['id_numb']:
            id_numb2 = request.GET['id_numb']
            id_numb = int(id_numb2)
            if id_numb == 1:
                # doesn't make it here - never get to this code, even when 1 is passed
                ....different code
            else:
                ....some code
        else:
            .... some other code