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

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Can someone please explain this.

So I made this line of code in my editor to be simple as possible without using another for block and it returns the email with letters changed. My question is why is not accepted? Just because the quiz mentions the for loop or because it's the code is not okey? I tried to pass the quiz in my way and i came up with this. Thank you.

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) %}
  <p>{{ User.email.replace(User.email.split('@')[0][1:], "*" * len(User.email.split('@')[0][1:])) }}</p>
{% endmacro %}

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Excellent novel solution idea!! You are very close to correct. The len() function is not available in the template language. Instead use the length filter:

{% macro hide_email(User) %}
  <p>{{ User.email.replace(User.email.split('@')[0][1:], "*" * (User.email.split('@')[0][1:] | length)) }}</p>
{% endmacro %}
Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

This is the first time I've seen this approach used on this challenge! Kudos to you!