for href not responding

I am trying to use url_for() to generate a url that will pass an argument to my Flask view. The client side html looks like this:

{% for account in accounts %}
<li class="list-group-item text-link-hover account clickable-panel"
    href="{{ url_for('accounts', account_id=account.id) }}"
    account-id={{ account.id }}>
    <a>{{ account.name }}</a>
</li>
{% endfor %}

Which seems to generate the correct html, as the result looks like this:

<li class="list-group-item text-link-hover account clickable-panel selected" href="/accounts/27" account-id="27">
      <a>Account Name</a>
</li>

And my flask view looks like this:

@app.route('/accounts/<int:account_id>')
def accounts(account_id):
    print(account_id)
    return 'account id is: ' + str(account_id)

Now the odd part is that when I click on the 'li' element in the browser - nothing happens. There is no url change, flask doesn't seem to recognise that the element was clicked at all ie it doesn't print anything

BUT when I manually change the url to "accounts/8" for example, flask correctly returns "account id is: 8"

Can anyone spot why the html isn't redirecting to the new flask view?


You can't set a href on a <li> element. It must go on the <a> tag inside.

链接地址: http://www.djcxy.com/p/71920.html

上一篇: 如何在Python中的SQL语句中使用变量?

下一篇: 为href没有响应