Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNursultan Bolatbayev
16,774 PointsWhat is advantage of form.as_p?
What is advantage of applying form.as_p instead of just form? I know that it will put each label and input into separate p. But why? Just for style selector or any other benefits?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou are correct that form.as_p
simply wraps all the elements in HTML <p>
tags. The advantage is not having to write a loop in the template to explicitly add HTML to surround each title and field.
There is also form.as_table
and form.as_ul
to also help set the form within the HTML context you wish. More details in Django form rendering options docs.
Nursultan Bolatbayev
16,774 PointsNursultan Bolatbayev
16,774 PointsOk. So it depends what output(more useful if I want as table or list) you want in html
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsExactly!