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 trialCross Ender
9,567 PointsHow do I do this?
I just can't figure this out.
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) %}
<p>{{ }}</p>
{% endmacro %}
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsHere are some hints. There are three things to print out.
- the first character of the email address, such as
user.email[0]
- replace second character up to the @ character of the email address with
*
- display the remaining @ character to the end of the email address
By splitting the email address on '@', the username would be the first entry, you can then loop over the characters in the results from .split('@')[0][1:]
replacing them with asterisks.
Finally print out the @ removed by the split, and the second item from the split which contains the domain address. Note you'll likely need to use split again since the second term might not have been saved .split('@')[1]
Final, hint: If you are seeing extra blank spaces between characters in the result, add a minus sign inside of the template brackets to signify to jinja that extra white space should be removed: {{-
or -}}
or {%-
or -%}
.
Post back if you have more questions. Good luck!!