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 Build a Social Network with Flask Takin' Names Macros

James J. McCombie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points

jinja2.exceptionsUndefinedError

Hello all,

up to the macros video, when I try to locally run the flask app, being roadblocked by the following error:

jinja2.exceptions.UndefinedError: 'forms.register object' has no attribute 'label'

this chunk of code is where the error comes in and program terminates terminates after jinja2 trying to do getattr

        {% if field.errors %}
            {% for error in field.errors %}
                <div class="notification error">{{ error }}</div>
            {% endfor %}
        {% endif %}
        {{ field(placeholder=field.label.text) }}
    </div>
{% endmacro %}

anyone else had this problem, or has an idea how to fix this?

thanks in advance

James

[MOD: added ```HTML+jinja formatting -cf]

2 Answers

Guy Scorpion
Guy Scorpion
11,053 Points

I'm only just up to this exercise so I'm still pretty new to this but it looks like the error isn't with your macro. It looks like it's saying forms.register has no label attribute. So there might be an error in your forms.py. Does your StringField() have a label:

StringField('FormLabel', validators=[ ... ])
James J. McCombie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points

Hello Guy,

thanks, yes there are labels for all the attributes on the register class.

Oddly, after I posted this on retrying over a few days, this error stopped happening, now I am stuck on an unexpected '}' which I cannot quite locate in the .html files or elsewhere, still its good practice I guess reading the debugger reports.

James