Tuesday, April 1, 2014

Re: Use custom HTML to render forms

You can use {{form.field_name}} to render the input tag, {{form.field_name.label}} to render the label and {{form.field_name.errors}} to render field errors. Simple example:

<div class="span6">
                            <div class="control-group required">
                            <label for="id_comments" class="control-label">{{ reorder_form.comments.label }}</label>
                            <div class="controls">
                                {{ reorder_form.comments.errors }}
                                {{ reorder_form.comments }}
                            </div>
                          </div>
                        </div>

To add attributes to the input tag, such as classes, placeholder etc. you need to add them as attrs dictionary parameter inside the widget class.

e.g. comment = forms.CharField(label="Please submit your comment below", widget=forms.Textarea(attrs={"class":"span6"}))

You can also create a filter for rendering your own markup. Perhaps you can take a look at bootstrap toolkit package for example. In particular {{form|as_bootstrap}}


On 1 April 2014 22:50, Mike Dewhirst <miked@dewhirst.com.au> wrote:
On 1/04/2014 8:12 PM, Daniel Roseman wrote:
On Tuesday, 1 April 2014 00:40:44 UTC+1, Fred DJar wrote:

    HELP PLEASE

I agree with DR but it might be interesting to know what your problem might be ...



No.

You don't get to demand that people help you. If someone knows the
answer to your question, and they have time to answer - and if they can
work out what you're asking, which isn't obvious - they will reply. But
if you want help on demand, you need to pay someone.
--
DR.

--
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+unsubscribe@googlegroups.com
<mailto:django-users+unsubscribe@googlegroups.com>.

To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>. <https://groups.google.com/d/msgid/django-users/162b8220-9c99-4f7f-ad36-7701d6a40451%40googlegroups.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/533AA81F.3070205%40dewhirst.com.au.

For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHqTbjmJDd6d08JFDmOhaf0WeysVBVe_PGjqk8q4pzB01mpnrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment