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
Timothy Obiso
11,683 PointsHow to customize variable on Jinja2 and WTForms render
I'm making a mini social media application using WTForms, Flask, Jinja, etc (using the same stuff as used in the Python Flask Social Media Application Course) and I was wondering if there was any way to customize the fields before it is rendered i.e. instead of just
<input type="checkbox"></input>
something like
<input type="checkbox" checked="checked" id="test" class="main"></input>
Thanks in advance
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsFrom what I understand reading the WTForms docs, you can pass arguments to the template tags and they will end up as HTML attributes:
{{ form.username(class="css_class") }}
The BooleanField class from WTForms allows you to pass a value for the default argument to output the checked="checked" attribute on the HTML element. All fields allow you to pass an id argument to set the HTML id attribute.
Hope that helps!