Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

newforms: Changed Form._html_output() to use dictionary-style format …

…strings for more flexibility. Thanks, Waylan Limberg

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 545ebf4 commit c50d333c23a3c53d05623ce15df79e624c57f37c @adrianholovaty adrianholovaty committed
Showing with 6 additions and 10 deletions.
  1. +6 −10 django/newforms/
16 django/newforms/
@@ -84,13 +84,9 @@ def _html_output(self, normal_row, error_row, row_ender, errors_on_separate_row)
top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors])
- label = bf.label_tag(escape(bf.verbose_name+':'))
- if errors_on_separate_row:
- if bf_errors:
- output.append(error_row % bf_errors)
- output.append(normal_row % (label, bf))
- else:
- output.append(normal_row % ((bf_errors, label, bf)))
+ if errors_on_separate_row and bf_errors:
+ output.append(error_row % bf_errors)
+ output.append(normal_row % {'errors': bf_errors, 'label': bf.label_tag(escape(bf.verbose_name+':')), 'field': bf})
if top_errors:
output.insert(0, error_row % top_errors)
if hidden_fields: # Insert any hidden fields in the last row.
@@ -105,15 +101,15 @@ def _html_output(self, normal_row, error_row, row_ender, errors_on_separate_row)
def as_table(self):
"Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
- return self._html_output(u'<tr><td>%s</td><td>%s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', True)
+ return self._html_output(u'<tr><td>%(label)s</td><td>%(field)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', True)
def as_ul(self):
"Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
- return self._html_output(u'<li>%s%s %s</li>', u'<li>%s</li>', '</li>', False)
+ return self._html_output(u'<li>%(errors)s%(label)s %(field)s</li>', u'<li>%s</li>', '</li>', False)
def as_p(self):
"Returns this form rendered as HTML <p>s."
- return self._html_output(u'<p>%s %s</p>', u'<p>%s</p>', '</p>', True)
+ return self._html_output(u'<p>%(label)s %(field)s</p>', u'<p>%s</p>', '</p>', True)
def non_field_errors(self):

0 comments on commit c50d333

Please sign in to comment.
Something went wrong with that request. Please try again.