jinja2 url_for多个争论jinja2.exceptions.TemplateSyntaxError:期望令牌',',得到':'

时间:2017-08-22 14:57:25

标签: python flask jinja2

当我尝试从jinja模板传递多个参数时,我遇到了解析错误:

jinja2.exceptions.TemplateSyntaxError:期望令牌',',得到':'

@classmethod
def follow_user(cls, followed_email, follower_email):
    with CursorFromConnectionFromPool() as cursor:
        cursor.execute('INSERT INTO connections(follower_id, followee_id) VALUES (%s, %s)',
                           (follower_email,followed_email))
@classmethod
def unfollow_user(cls, followed_email, follower_email):
    with CursorFromConnectionFromPool() as cursor:
        cursor.execute("DELETE from connections WHERE follower_id = '{}' AND followee_id = '{}' ",
                           (follower_email, followed_email))
{% if is_following %}
 <a class="btn btn-danger" href="{{ url_for('user.unfollow_user',followed_email:followed.email,follower_email:follower_email) }}" role="button">Unfollow</a>
 {% else %}
 <a class="btn btn-success" href="{{url_for('user.follow_user',followed_email:followed.email,follower_email:follower_email) }}" role="button">Follow</a>
{% endif %}

1 个答案:

答案 0 :(得分:0)

这一行:

<a class="btn btn-danger" href="{{ url_for('user.unfollow_user',followed_email:followed.email,follower_email:follower_email) }}" role="button">Unfollow</a>

应替换为:

<a class="btn btn-danger" href="{{ url_for('user.unfollow_user',followed_email=followed.email,follower_email=follower_email) }}" role="button">Unfollow</a>

并在第二行使用相同的'=':

<a class="btn btn-success" href="{{url_for('user.follow_user',followed_email=followed.email,follower_email=follower_email) }}" role="button">Follow</a>

将参数传递给url_for中的参数时,您应该使用=