Django Forms: Radio buttons and label displayed in the same line?

2,940 views
Skip to first unread message

voss

unread,
Sep 30, 2011, 4:03:55 PM9/30/11
to django...@googlegroups.com
Hello all,

Is it possible to display radio buttons and label in the same line using Django forms? Below is an example:

_Choices = (
    (1,        'A'),
    (2,        'B'),
    (3,        'C'),
)

class QuestionForm(forms.Form):
    question  = forms.ChoiceField(label='Please choose one!', choices=_Choices, widget=forms.RadioSelect())

How to display "Please choose one!",  A, B, and C all on the same line?

Thank you!

Ilian Iliev

unread,
Sep 30, 2011, 4:13:22 PM9/30/11
to django...@googlegroups.com
Hi, you can do it with CSS styling, custom widget or custom HTML.
Check this link for the custom HTML approach - http://ilian.i-n-i.org/django-forms-choicefield-and-custom-html-output/
This is not the best one but if you need it only for a single place go for it.

-- 
eng. Ilian Iliev
Web Software Developer

Mobile: +359 88 66 08 400
Website: http://ilian.i-n-i.org

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/97uo1h7c90IJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


voss

unread,
Sep 30, 2011, 4:16:49 PM9/30/11
to django...@googlegroups.com
Thanks, eng. Ilian Iliev. I will definitely take a look!


voss

unread,
Sep 30, 2011, 7:07:41 PM9/30/11
to django...@googlegroups.com
Hi eng. Ilian Iliev,

I visited your page (http://ilian.i-n-i.org/django-forms-choicefield-and-custom-html-output/) and now my code works!

After visiting the page, though, I realized that I'd asked a stupid question. What I ended up doing is that I started a Python interactive interpreter, printed the form as HTML, copied and pasted it to the template , and did some CSS styling as you suggested. It is now working with my original views.

Once again, thank you for the great link! It is very helpful!!

cheers,

    voss  

Ilian Iliev

unread,
Oct 1, 2011, 12:12:02 PM10/1/11
to django...@googlegroups.com
I am glad I could help.

-- 
eng. Ilian Iliev
Web Software Developer

Mobile: +359 88 66 08 400
Website: http://ilian.i-n-i.org

Reply all
Reply to author
Forward
0 new messages