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

Create a macro named hide_email. It should take a User as an argument. Print out the email attrib

Challenge Task 1 of 1

Create a macro named hide_email. It should take a User as an argument. Print out the email attribute of the User in the following format: t***@example.com for the email test@example.com. This will require splitting the email string and using a for loop.

what video should I be watching?

I cannot figure out this exercise from looking at my notes. Please help. =)

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) %}
    {{ form.hidden_tag() }}
    {% for field in form %}
    {{ render_field(field) }}
    {% endfor %}
{% endmacro %}

2 Answers

David Leacock
David Leacock
8,532 Points

If the email address is 'name@domain.com' you can split it like this

name, domain = string.split('@') that'll give you name = 'name' and domain = 'domain.com'.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You can do this entire challenge just in the templates/macro.html file. You don't need to modify the Flask app at all.

Here are your steps:

  1. Split the email address into its two main parts
  2. Print the first letter of the "name" part of the email
  3. Print asterisks for the remaining letters
  4. Print the @ symbol
  5. Print the domain name

Done!

Hi Kenneth. Is there a website we can see the documentation of the Jijnja2 required to pass this challenge? I've been looking for but can't find it.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I don't know that there's a site with this exact code on it, no. I know there's a solution or two posted to the forums already.

Chen Wang
Chen Wang
7,371 Points

I know how to write the above process, but I cannot pass the challenge.

It keeps saying that I have some errors, but don't tell me what error it is.

Is there a way to debug in Jinjia's template?

My point is, if it's just python, I can figure it out. However, for this template, I don't know what to do when I have bugs.

email = email.split('@')[0].replace(email.split('@')[0][1 : len(email.split('@')[0])], '*' * (len(email.split('@')[0]) - 1)) + '@' + email.split('@')[1]

this miraculously did not work.