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 trialmichaelangelo owildeberry
18,173 PointsCreate 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. =)
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)
{% macro hide_email(User) %}
{{ form.hidden_tag() }}
{% for field in form %}
{{ render_field(field) }}
{% endfor %}
{% endmacro %}
2 Answers
David Leacock
8,532 PointsIf 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
Treehouse Guest TeacherYou 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:
- Split the email address into its two main parts
- Print the first letter of the "name" part of the email
- Print asterisks for the remaining letters
- Print the
@
symbol - Print the domain name
Done!
Rodrigo Muñoz
Courses Plus Student 20,171 PointsHi 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
Treehouse Guest TeacherI 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
7,371 PointsI 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.
Fredrik August Madsen-Malmo
16,261 Pointsemail = 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.