Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django HttpResponse Location redirect

Tags:

python

django

I am trying to redirect to another page when http response is True I have added response['Location'] = 'login.html' but it's not working, I am getting a page with True written but not the login page. Can you help me I am new to django.

I have written this code

if user_obj:
    response = HttpResponse(True)
    response['Location'] = 'login.html'
    return response
else:
    return HttpResponse(False)
like image 609
Rahul Raj Avatar asked Oct 30 '25 02:10

Rahul Raj


1 Answers

from django.urls import reverse

return HttpResponseRedirect(reverse('url_name'))

like image 75
Shah Vipul Avatar answered Oct 31 '25 17:10

Shah Vipul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!