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

Arihant Jain
Arihant Jain
306 Points

Confusing

unable to find where the mistake is

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) %}
{% array_of_strings = User.email.split('@') %}
{% first_string = array_of_strings[0] %}
<div> {{ first_string[0] }}</div>
  {% for length in (len(first_string)-1) %}
    <div>*</div>
  {% endfor %}  
{% second_string = array_of_strings[1] %}
  {% for character in list(second_string) %}
    <div> {{ character }}</div>
  {% endfor %}
{% endmacro %}

1 Answer

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

In your html file here is one way to do it:

{% macro hide_email(user) %} {%- set handle, domain = user.email.split("@") -%} {%- set hidden = handle[0] + ("*" * handle[1:]|length) -%} {{ hidden + "@" + domain }} {%- endmacro %}