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

Nadine Abella
Nadine Abella
1,032 Points

hide_macro help

my code works on idle but kinda confused how to translate it into a macro

this is basically my function

def hide_email(email):
    return email[0] + "*" * len(email[1:email.index("@")]) + email[email.index("@"):]
templates/macro.html
{% macro hide_email(email) %}   
    {{email[0] + "*" * len(email[1:email.index("@")]) + email[email.index("@"):]}}
{%endmacro%}

1 Answer

Hi Nadine Abella, you're quite close.

First up, it's the user that is being passed to the template, not the email, so if you change all instances of email to user.email, that will make sure it's the email attribute being manipulated and printed.

Second, I don't think the string multiplication works here, so you'll instead need to refactor the code to use the Flask/Jinja for loop.

Lastly, instead of concatenating the strings with +, separate them into different blocks (you'll need to do this with the for loop anyways).

Good luck! This is definitely one of the trickier challenges, and there are a ton of questions about it in the forums!