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


Flask social network - Macro code challenge formatting?

I'm trying to get the format of the macro correct for the challenge, and I can quite get it!

Additional question, what's the best way to test the code for challenges in this module? The challenges remarks don't always give that much information, so debugging it externally is quite helpful!

from flask import Flask, render_template

app = Flask(__name__)

def index():
    class User:
        email = None
    user = User()
    user.email = 'kenneth@teamtreehouse.com'
    return render_template('user.html', user=user)
{% macro hide_email(User) %}

{{ email = User.email.split('@') }}
{{ email[0] = email[0][0]+'x'*len(email[0][1:]) }}
{{ '@'.join(email) }}

{% endmacro %}

Knowing Jinja formatting is of the utmost importance.

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Trevor.

I remember this challenge causing troubles to myself as well and when I looked at the forums to understand more about it I saw that there were a few threads on this already.

From your code I see you got the idea of the things that need to be done here in order to achieve the desired output, but please note that flask (and in particular jinja2) turn out to have specific syntax that is a little different from plain python.

This was the best thread for me to get it going, I recommend you give it a read as it explains things better than I could do probably:


Regarding the debugging part of the question: yes code challenge don't always provide much information about debugging but I think this is done on purpose as code is not huge for now and they probably want us to be able to debug on our own, but in your specific case (if I remember correctly) once the syntax of the code is fine the debugger helps out a bit.


Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Quite often it's just impossible for us to provide adequate debugging in code challenges. The 'preview' pane should show you what your macro is outputting, though.