Click here to Skip to main content
15,352,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Richard MacCutchan 16-Feb-19 5:25am
   
What are the values in the radio fields when you run the code?
Member 14068174 16-Feb-19 22:31pm
   
The values are two followers and like. If user will click on follower radio button it should take him to follower page but if he clicks on likes radio button then it should take him to likes page but it takes them on same page no matter what the user chooses

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900