Changes between Version 3 and Version 4 of TemplatedForm
- Timestamp:
- Mar 21, 2007, 2:41:17 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TemplatedForm
v3 v4 1 1 == Subclassing newforms Form.form to rendering form via django template == 2 2 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. 3 Newforms are made to make any kind of customizations easy. Sometimes standard methods of rendering HTML/XML/other content of 4 the django.newforms is not enough to completely satisfy all web design needs so you may want to present forms in own 5 templates. 5 6 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. 7 Using templates to render output as HTML or XML is straighforward, and in many cases easier then using standard approach. 8 8 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 == 12 10 13 11 1. Create file in your project: … … 24 22 def output_via_template(self): 25 23 "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()] 31 26 c = Context(dict(form = self, bound_fields = bound_fields)) 32 27 t = loader.get_template('newforms/form.html')