[Solved] I Want to access the variable of a if statement in the function .Python


Set your variable before the if :

def Home(request):#django
    city = ''
    if request.method == 'POST':
        city = request.POST.get('search')
        print(city)
        
    URL = f'http://api.openweathermap.org/data/2.5/weather?q={city}

0

solved I Want to access the variable of a if statement in the function .Python