title: django - how to override a form textbox widget with a string?
body: <p>Still fairly new to django and python...</p>
  
  <p>I've defined two forms as follows:</p>
  
  <pre><code> class PasswordForm(forms.Form):
       def __init__(self, *args, **kwargs):
           self.name={'label':'Name', 'data':''}
  
       def get_name(self):
           return self.name['data']
  
       def set_name(self, name):
           self.name['data'] = name
  
       name = property(get_name, set_name)
  
       pass1 = forms.CharField(max_length=20)
       pass2 = forms.CharField(max_length=20)
  
  
   class UserForm(PasswordForm):
       name = forms.CharField(max_length=20)
  </code></pre>
  
  <p>The reason I've set it up like this is as follows:</p>
  
  <ul>
  <li>trying to use a single template to handle both forms</li>
  <li>sometimes only want to validate PasswordForm fields, other times both UserForm AND PasswordForm fields, hence two forms</li>
  <li>in the template, sometimes want to display name as a textbox input, and other times as just a string showing the value of name (i.e. uneditable)</li>
  </ul>
  
  <p>I thought I would be able to loop over something like the following in the template</p>
  
  <pre><code> {{ form.field.label }} {{ form.field }}
  </code></pre>
  
  <p>What ends up happening is that the development server crashes (i.e. 'python manage.py runserver') hard - no error messages, just quits.</p>
  
  <p>Obviously, I've done something wrong, but don't know what. Is it possible to override the textbox input with a string in such a way that the template is none the wiser? If so, how do I go about doing it?</p>
  
  <p>Thanks for your help!</p>
  
  <p>W.</p>
  
  <p><strong>EDIT:</strong>
  As per Pasty Legs' answer, the thing to do is to override the widget used. A couple of tweaks to the syntax in widgets.py for it to work for me:</p>
  
  <pre><code> from django.forms import widgets                                                                         
   from django.utils.safestring import mark_safe 
  
   class StringWidget(widgets.Input):                                                                       
       def render(self, name, value, attrs=None):                                                           
           # Create a hidden field first                                                                    
           hidden_field = widgets.HiddenInput(attrs)                                                        
           return mark_safe(u'%s %s' % (value, hidden_field.render(value, attrs))) 
  </code></pre>