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 trial

Python Django Forms Forms Showing a Form in a View

Nursultan Bolatbayev
Nursultan Bolatbayev
16,774 Points

What 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
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You 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
Nursultan Bolatbayev
16,774 Points

Ok. So it depends what output(more useful if I want as table or list) you want in html