On 2007-04-25 17:27:26 -0600, RollyF <[EMAIL PROTECTED]> said: > > canen, > > Thank you for your reply but I am not sure if I am getting this right. > I am getting an "Exception Value: __init__() got an unexpected > keyword argument 'attrs'" with the following code > > class CreateGuestUserForm(forms.Form): > first_name = forms.CharField(label='First Name', > attrs={'class':'left'}) > > I stepped through django code and found the following: > >>>> > class CharField(Field): > def __init__(self, max_length=None, min_length=None, *args, > **kwargs): > self.max_length, self.min_length = max_length, min_length > super(CharField, self).__init__(*args, **kwargs) > > class Field(object): > widget = TextInput # Default widget to use when rendering this > type of Field. > hidden_widget = HiddenInput # Default widget to use when rendering > this as "hidden". > > # Tracks each time a Field instance is created. Used to retain > order. > creation_counter = 0 > > def __init__(self, required=True, widget=None, label=None, > initial=None, help_text=None): > >>>> > > I am new to python and django, but it looks like the Field's init > arguments do not recognize "attrs." > > Thanks > Rolly > > On Apr 25, 3:04 pm, canen <[EMAIL PROTECTED]> wrote: >> You would use the attrs argument when declaring the field. >> >> ..... >> first_name = CharField('First name', attrs={'class': 'left'}) >> ..... >> >> On Apr 25, 1:02 pm, RollyF <[EMAIL PROTECTED]> wrote: >> >>> How do I do this using newforms if I want my output to be: >> >>> <label for="id_firstname" class="left">First name:</label> >> >>> I want to know how to pass the "class" to the output. >> >>> TIA, >>> Rolly > > > I don't think it's possible to add a class attr to the label tag that Django generates through its lazy form methods. You can pass an attrs dictionary to a widget. Check into widgets, there are some good examples in the newforms_admin branch. The only other alternative to specifying attrs on the label tag is to manually create the form in the template. Like:
{{ form.field.label }} - {{ form.field }} Isn't there a ticket in Trac that tries to allow for attrs in the label tag? It has something to do with errors and required classing of labels for easier output. -- Brian Rosner http://www.brosner.com/blog --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---