Hello I am trying to make a decision based radio buttons, I am trying to land the client on the page based on which radio button he checked but it lands me on same page no matter if I choose another button. It stills loads me to the same page
The code is below:
views.py
def index(request):
form = Form()
radio = Radio()
if request.method == 'POST':
form = Form(request.POST)
if form.is_valid():
form.save(commit = True)
if radio.fields['display'].choices[0]:
return render(request,'insta_app/likes.html')
elif radio.fields['display'].choices[1]:
return render(request,'insta_app/follower.html')
# return HttpResponseRedirect(reverse('insta_app:likes'))
return render(request,'insta_app/index.html',{'form':form,'radio':radio})
Forms.py
DISPLAY_CHOICES = [
(0,'Followers'),
(1,'Likes')
]
class Radio(forms.Form):
display = forms.ChoiceField(widget = forms.RadioSelect, choices = DISPLAY_CHOICES)
HTML code:
{% csrf_token %}
{{ form.as_p }}
What you want ?
<!--
Followers -->
{{ radio.display.0 }}
{{ radio.display.1 }}
What I have tried:
I tried stack overflow and also tried to change index.