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 Build a Social Network with Flask Broadcasting Add Some Layout

Tommy Binkley
Tommy Binkley
18,584 Points

Encountered unknown tag 'endfor'

I have watched the video twice and redid my code with the {% if current_user.is_authenticated %} and I tried it with {% if current_user.is_authenticated() %} and both of them don't work I keep getting the error "Encountered unknown tag 'endfor'. Jinja was looking for the following tags: 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'." And I change it to and if statement then it changes the error to something else. I appreciate the help I've been stuck on it for a few days

Thanks

2 Answers

Tatiana Vasilevskaya
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 Points

There are two things I see.

You have {{ endif }} instead of {% endif %} in

<h1>Hello{% if current_user.is_authenticated %} {{ current_user.username }}{{ endif }}!</h1>

You're missing a % in

{ for category, message in messages %}
Tommy Binkley
Tommy Binkley
18,584 Points

<!DOCTYPE html> <html class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>{% block title %}TwoCans{% endblock %}</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="/static/css/normalize.min.css"> <link rel="stylesheet" href="/static/css/main.css">

    <!--[if lt IE 9]>
        <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <script>window.html5 || document.write('<script src="/static/js/vendor/html5shiv.js"><\/script>')</script>
    <![endif]-->
</head>
<body>

    <header>

      <div class="row">

        <div class="grid-33">

          <a href="{{ url_for('index') }}" class="icon-logo"></a>

        </div>

        <div class="grid-33">

            <!-- Say Hi -->
            <h1>Hello{% if current_user.is_authenticated %} {{ current_user.username }}{{ endif }}!</h1>

        </div>

        <div class="grid-33">

            <!-- Log in/Log out -->
            {% if current_user.is_authenticated() %}
            <a href="{{ url_for('logout') }}" class="icon-power" title="Log out"></a>
            {% else %}
            <a href="{{ url_for('login') }}" class="icon-power" title="Log in"></a>
            <a href="{{ url_for('register') }}" class="icon-profile" title="Register"></a>
            {% endif %}

        </div>

      </div>

    </header>

    <!-- Flash messages -->
    {% with messages = get_flashed_messages(with_categories=True) %}
        {% if messages %}
            { for category, message in messages %}
                <div class="notification {{ category }}">{{ message }}</div>
            {% endfor %}
        {% endif %}
    {% endwith %}

    <div class="row">

      <div class="main">

        <nav>

          <a href="{{ url_for('index') }}">All</a>

        </nav>

        {% block content %}{% endblock %}

      </div>

    </div>

    <footer>

      <div class="row">

        <p>A Social App built with Flask<br>by <a href="http://teamtreehouse.com">Treehouse</a></p>

      </div>

    </footer>

    <script src="/static/js/vendor/disTime.min.js"></script>
    <script src="/static/js/main.js"></script>

</body>

</html>