I'm in the process of trying to minimize the amount of code I need to use 
to render a form with bootstrap styling with the hope of rendering with 
just {{ form }} but I haven't yet managed to find a way to render a 
BooleanField with the checkbox before the text.

 
from django.forms import Form, BooleanField

class MyForm(Form): 
    field = BooleanField(label='Test Label') 

MyForm().as_table()

 

The above test code will output 

     
<tr><th><label for="id_field">Test Label:</label></th><td><input class="" id
="id_field" name="field" type="checkbox" /></td></tr>

But what I'm hoping to achieve is the same look and feel as shown in the 
bootstrap docs <http://getbootstrap.com/css/#forms-example>.

     
<label for="id_field"><input class="" id="id_field" name="field" type=
"checkbox" />Test Label:</label>

 The problem in doing this is that the rendering is handled via the form, 
where the label and the field are positioned/rendered separately as shown 
in the source 
<https://github.com/django/django/blob/master/django/forms/forms.py#L259>, 
, and I have yet to find a place to override that will allow me to render 
the widget inside of the label...

 

Any ideas how I can achieve this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c92f9f04-6c72-4d2d-8ff4-6de34be9f00e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to