python – Django template radio button auto select-ThrowExceptions

Exception or error:

I am developing an app with django. Here is the screenshot. I need to know when user will select on a plan in the next page that plan radio button should auto select.

I am able to grab all the information regarding the selected plan but dont understand how to select that plan’s radio button.

here is the screenshots. Let me know anyone has the answer.

enter image description here

here is the next image where the radio buttons are present.

enter image description here

How to solve:

You could store the selected plan inside a sessions key and then check if that key exists in the next page… something like:

# in your first view set the session keys of posted plan

if 'express' in request.POST:
   request.session['express'] = 'express chosen' # strings are easier to handle

# add the other plans to the if statement
# in the next page's view function, add keys to context if they are in the session framework like so

if 'express' in request.session:
    express = request.session['express']

# add the other plans to the if statement

Now in the template, check if the variables exist to select option as default…

 <input type="radio" {%if express%}checked{%endif%}>

 <!-- repeat for the other plans -->

Leave a Reply

Your email address will not be published. Required fields are marked *