Code

Changes between Version 3 and Version 4 of TemplatedForm


Ignore:
Timestamp:
03/21/07 00:41:17 (7 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TemplatedForm

    v3 v4  
    11== Subclassing newforms Form.form to rendering form via django template == 
    22 
    3 Sometimes standard methods of rendering HTML/XML/other content of the django.newforms is not enough to completely 
    4 satisfy all web design needs. So sometimes it is better to customize your forms completely. 
     3Newforms are made to make any kind of customizations easy. Sometimes standard methods of rendering HTML/XML/other content of  
     4the django.newforms is not enough to completely satisfy all web design needs so you may want to present forms in own 
     5templates. 
    56 
    6 Using templates to render output as HTML or XML is straighforward and uses less code then as_table() counterpart 
    7 implemented now in the core newforms, so I hope technique explained here will be helpful. 
     7Using templates to render output as HTML or XML is straighforward, and in many cases easier then using standard approach. 
    88 
    9 The above example has been created specifically to mark required fields with red asterisk. 
    10 In fact all you need to do to use this, is to add 3 small files to your project, and replace 
    11 forms.Form to TemplatedForm class. Step by step explanations: 
     9== Step by step guide == 
    1210 
    13111. Create file in your project: 
     
    2422    def output_via_template(self): 
    2523        "Helper function for fieldsting fields data from form." 
    26         bound_fields = [] 
    27         for name, field in self.fields.items(): 
    28             bf = BoundField(self, field, name) 
    29             bound_fields.append(bf) 
    30          
     24        bound_fields = [BoundField(self, field, name) for name, field \ 
     25                        in self.fields.items()] 
    3126        c = Context(dict(form = self, bound_fields = bound_fields)) 
    3227        t = loader.get_template('newforms/form.html')