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

James Mulholland
seal-mask
.a{fill-rule:evenodd;}techdegree
James Mulholland
Full Stack JavaScript Techdegree Student 20,944 Points

No idea where I'm going wrong here. Help much appreciated. Here's my code: https://github.com/MulhollandCode/treehouse/

No idea.

lunch.py
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    class User:
        email = None
    user = User()
    user.email = 'kenneth@teamtreehouse.com'
    return render_template('user.html', user=user)
templates/macro.html
{% macro hide_email(User) %}
    <div>
        {{ hide = User.email[0] }}
        {% for i in range(1, User.email.index('@')) %}
            {{ hide += '*' }}
        {% endfor %}
        {{ hide += `User.email[User.email.index('@'):] }}
        <div>{{ hide }}</div>
    </div>
{% endmacro %}

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are on the right path. Instead of concatenating new characters to hide, simply print them out:

{% macro hide_email(User) %}
        {{ User.email[0] }}
        {% for i in range(1, User.email.index('@')) %}
            {{ '*' }}
        {% endfor %}
        {{ User.email[User.email.index('@'):] }}
{% endmacro %}

This gets you most of the way there: k * * * * * * @treehouse.com, but there are extra spaces. Remove the space by adding minus ("-") signs inside the template tags and variables to indicate no whitespace:

{% macro hide_email(User) %}
        {{ User.email[0] -}}
        {% for i in range(1, User.email.index('@')) %}
            {{- '*' -}}
        {% endfor %}
        {{- User.email[User.email.index('@'):] }}
{% endmacro %}