One suggestion is to simply reference
YourFormName.fields['e_mail'].label in the code that renders the
template, then pass it as a variable to the template.
As an example, assuming e_mail is set up in YourFormName as below:
from django.shortcuts import render_to_response
form = YourFormName()
e_mail_label = form.fields['e_mail'].label
variables = RequestContext(request, {'form' : form})
return render_to_response('your_template_page.html', {'e_mail_label' :
e_mail_label}, context_instance=variables}
You can then slip {{ e_mail_label }} into the HTML document wherever you
need to and have it consistently match whatever you have stored in your
forms file. I.e.,
<label for="id_e_mail">{{ e_mail_label }}</label>
A minor improvement in the way of aesthetics, but in the way of rapid
updates to the code (same principle as CSS) it should help. No more ugly
HTML clutter!
Best of luck,
--Mick
On Mon, 2011-01-24 at 17:07 -0800, John Yeukhon Wong wrote:
> In forms,py, we can simple do this
> e_mail = forms.EmailField(label='Your e-mail address')
>
> this will work and be use if we use {{ form.as_table}} for example.
>
> But if we instead use our own customization, because it's too
> restricted to use the auto form render, when it comes to labels, we
> have to manually specify it
> <label for="id_e_mail">Your e-mail address</label>
>
> But this may looks ugly. Is there a way to load the label from
> forms.py even if we are not using form.as_ ??
>
> Thanks.
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.