Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 25, 2011 01:07:51

John Y.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

label when customize django form


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 django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 25, 2011 03:09:35

Michael O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

label when customize django form


One suggestion is to simply reference
YourFormName.fields.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.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 django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 25, 2011 06:00:38

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

label when customize django form


Have you checked `form.email.label_tag`?

> > But this may looks ugly. Is there a way to load the label from
> > forms.py even if we are not using form.as_ ??

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support