Form.as_table()
Finally, as_table()
outputs the form as an HTML <table>
. This is exactly the same as print
. In fact, when you print
a form object, it calls its as_table()
method behind the scenes:
1 2 3 4 5 6 7 8 | >>> f = ContactForm() >>> f.as_table() '<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required /></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required /></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required /></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>' >>> print (f.as_table()) <tr><th><label for = "id_subject" >Subject:< / label>< / th><td>< input id = "id_subject" type = "text" name = "subject" maxlength = "100" required / >< / td>< / tr> <tr><th><label for = "id_message" >Message:< / label>< / th><td>< input type = "text" name = "message" id = "id_message" required / >< / td>< / tr> <tr><th><label for = "id_sender" >Sender:< / label>< / th><td>< input type = "email" name = "sender" id = "id_sender" required / >< / td>< / tr> <tr><th><label for = "id_cc_myself" >Cc myself:< / label>< / th><td>< input type = "checkbox" name = "cc_myself" id = "id_cc_myself" / >< / td>< / tr> |
Please login to continue.