learnDjango 3
as_p()¶
<dl class="method"> <dt style="font-family:Roboto, Corbel, Avenir, 'Lucida Grande', 'Lucida Sans', sans-serif;"> <tt class="descclassname" style="font-family:'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;line-height:14px;color:rgb(12,75,51);font-size:1em;">Form.</tt> <tt class="descname" style="font-family:'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;line-height:14px;color:rgb(12,75,51);font-size:1em;">as_p</tt>() ¶ </dt> </dl><tt class="docutils literal" style="font-family:'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;line-height:14px;color:rgb(12,75,51);font-size:1em;font-weight:700;">as_p()</tt> 渲染表单为一系列的<tt class="docutils literal" style="font-family:'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;line-height:14px;color:rgb(12,75,51);font-size:1em;font-weight:700;"><p></tt> 标签,每个<tt class="docutils literal" style="font-family:'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;line-height:14px;color:rgb(12,75,51);font-size:1em;font-weight:700;"><p></tt> 标签包含一个字段:
>>> f = ContactForm()
>>> f.as_p()
'<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>'
>>> print(f.as_p())
<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>
<p><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" /></p>
<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>ㄛ