Categories
Python Answers

How to allow only one radio button to be checked with Python Django?

Spread the love

Sometimes, we want to allow only one radio button to be checked with Python Django.

In this article, we’ll look at how to allow only one radio button to be checked with Python Django.

How to allow only one radio button to be checked with Python Django?

To allow only one radio button to be checked with Python Django, we set the radio buttons in the group to the same name.

For instance, we write

{% for each in AnswerQuery %}
    <form action={{address}}>
        <span>{{each.answer}}</span><input type='radio' name="radAnswer" >
        <span>Votes:{{each.answercount}}</span>
        <br>
    </form>
{% endfor %}

to set the name attribute of all radio buttons to radAnswer.

Then we can only select one button from the group.

Conclusion

To allow only one radio button to be checked with Python Django, we set the radio buttons in the group to the same name.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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