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

  • Home
  • SEARCH
  • 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 3494388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:00:00+00:00 2026-05-18T12:00:00+00:00

Suppose I created a django form that has a radio box selection in it:

  • 0

Suppose I created a django form that has a radio box selection in it:

class PlaylistsForm(forms.Form):
    choices=forms.ChoiceField( widget=forms.RadioSelect(), CHOICES,label="choices")

If I try to instantiate the form and do form.choices I get an error that the instance has no attribute choices. Can you refer me to somewhere where it explains the magic behind the creation of the fields, and secondly, how can I access the fields?

EDIT:
To make it clear: I want to know why, given an instance of PlaylistsForm, doing
print form.choices I get an error saying there’s no such attribute. What dark magic is happening behind the scenes here?

  • 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-05-18T12:00:00+00:00Added an answer on May 18, 2026 at 12:00 pm

    Presuming CHOICES is a tuple of options for the field, the change is relatively simple:

    class PlaylistsForm(forms.Form):
        choices=forms.ChoiceField(widget=forms.RadioSelect(),
                                  choices=CHOICES,
                                  label="choices")
    

    See the documentation of ChoiceField, and the documentation of choices for more detail.

    Changes post your edit:

    Short answer

    You’re probably confusing your field called choices, and the attribute choices on your choices field.

    Say you’ve got a form:

    my_form = PlaylistsForm()
    

    You could access the choices attribute of the choices field like this:

    my_form.fields['choices'].choices
    

    Long answer

    I didn’t know how to do what you wanted, so I stuck a import pdb; pdb.set_trace() just after I declared a form, like this:

    form = PlaylistsForm()
    import pdb; pdb.set_trace()
    

    Then, using the development server, I opened up a URL which mapped to the view with my new import pdb; pdb.set_trace() in it. Switching over to my command prompt, I could inspect what attributes and methods existed on my form object at the debug prompt:

    (Pdb) dir(form)
    

    This showed me form had a fields attribute, so I looked at it:

    (Pdb) form.fields
    

    This showed me form.fields is a dict, with values being Field objects, I picked out the choices field, and looked to see what attributes it had:

     (Pdb) dir(form.fields['choices'])
    

    This showed me that form.fields['choices'] had a choices attribute:

    (Pdb) form.fields['chiices'].choices
    [('', '---------'), (1L, My Playlist')]
    

    This is probably what you’re looking for.

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

Sidebar

Related Questions

I've created a web page that is suppose to look like it has tabs
Suppose an application with some forms and only one data module are created at
Let's suppose I have created a view that shows some kind of stories. But
In my Django application I have Guest user accounts that are created for all
I've got a Django project that has multiple settings files (www site, mobile site,
Suppose I created a custom web application that consists of: several assembly DLLs: web
Suppose I created index with descending order CREATE INDEX `MyTable.MyIndex` USING BTREE ON `MyTable`
Suppose I created a cookie with one year expiration in domain abc.com and now
What is the best practice for releasing a simple software? Suppose I created a
Suppose I have created one jQuery function to check if elements exist or not

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.