Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:22:59+00:00 2026-06-07T04:22:59+00:00

If I have a model that contains a ChoiceField with a RadioSelect widget, how

  • 0

If I have a model that contains a ChoiceField with a RadioSelect widget, how can I render the radio buttons separately in a template?

Let’s say I’m building a web app that allows new employees at a company to choose what kind of computer they want on their desktop. This is the relevant model:

class ComputerOrder(forms.Form):
    name = forms.CharField(max_length=50)
    office_address = forms.Charfield(max_length=75)
    pc_type = forms.ChoiceField(widget=RadioSelect(), choices=[(1, 'Mac'), (2, 'PC')])

On the template, how do I render just the Mac choice button? If I do this, it renders all the choices:

{{ form.pc_type  }}

Somewhat naively I tried this, but it produced no output:

{{ form.pc_type.0 }}

(I found a few similar questions here on SO:

In a Django form, how do I render a radio button so that the choices are separated on the page?
Django Forms: How to iterate over a Choices of a field in Django form

But I didn’t feel like they had good answers. Is there a way to resurrect old questions?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:23:02+00:00Added an answer on June 7, 2026 at 4:23 am

    Django 1.4+ allows you to iterate over the choices in a RadioSelect, along with the lines of

    {% for choice in form.pc_type %}
      {{ choice.choice_label }}
      <span class="radio">{{ choice.tag }}</span>
    {% endfor %}
    

    I’m not sure if this change allows you to use the syntax you describe ({{ form.pc_type.0 }}) — if not, you could work around this limitation with the for loop above and a tag like {% if forloop.counter0 == 0 %}.

    If you’re tied to Django < 1.4, you can either override the render() method as suggested or go with the slightly-more-verbose-but-less-complicated option of building up the form field yourself in the template:

     {% for choice in form.pc_type.field.choices %}
       <input name='{{ form.pc_type.name }}' 
         id='{{ form.pc_type.auto_id }}_{{ forloop.counter0 }}' type='radio' value='{{ choice.0 }}'
         {% if not form.is_bound %}{% ifequal form.pc_type.field.initial choice.0 %} checked='checked' {% endifequal %}
       {% else %}{% ifequal form.pc_type.data choice.0 %} checked='checked' {% endifequal %}{% endif %}/>
       <label for='{{ form.pc_type.auto_id }}_{{ forloop.counter0 }}'>{{ choice.1 }}</label>
     {% endfor %}
    

    (choice.0 and choice.1 are the first and second items in your choices two-tuple)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I have a model object that contains a collection lets say
Say I have an assets model that contains two columns: Assets ownership:string lease_id:integer #
I have a model that contains an Address property and Latitude / Longitude properties.
I have a model that contains a foreign key value, then in the form
I have a model that contains one-to-one fields to other models. I over rid
I have a Model that contains a List of a custom type. I want
I have a model form that contains a DecimalField() with max_digits set to 5.
I have a model window that contains expander control. This expander control when expanded
I have a view model that contains a Product class type and an IEnumerable<
I have the model Member that contains all informations about the registered member on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.