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 trialDarel Bitsy
6,910 PointsFlask macro task change test@bar.com to t**@bar.com
Well, I'm not sure a did the right way and I'm a little bit out of ideas, I tried this on my computer working well, since we can use python in template with Jinja so added this idea but I can't pass the challenge
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) %}
{% set temp_list = User.email.split('@') %}
{% set temp_list2 = [] %}
{% final = '' %}
{% for letter in temp_list[0] %}
{% if letter == list(temp_list[0])[0] and x not in temp_list2 %}
{% temp_list2.append(letter) %}
{% endif %}
{% temp_list2.append('*') %}
{% endfor %}
{% set temp_list[0] = '@' %}
{% for letter in temp_list2[::-1] %}
{% temp_list.insert(0, letter) %}
{% endfor %}
{% set final = ''.join(temp_list) %}
{{ final }}
1 Answer
Ryan S
27,276 PointsHi Darel,
I had a difficult time with this one as well. Although your logic looks good for running it in Python, it can be done without if statements or appending lists or any of that in Jinja. The trick is to print out each character one at a time rather than try to rejoin everything into a single variable at the end. You got the right idea using indexes and slices though.
You can assign temporary variables using "with":
{% with part_one, part_two = User.email.split('@') %}
{{ part_one[0] }} .....
And you don't need to assign "*" or "@" to anything, they can simply be inserted where you want them outside of the curly braces. For example: {% ...code.. %}@{%...code...%}.
Also, make sure that everything that you want printed is coded on the same line, otherwise you will get whitespace between the characters.
Hope this helps,
Darel Bitsy
6,910 PointsDarel Bitsy
6,910 PointsThanks for the answer , already solved the issue and you are right about the process