Question

The button below used to work when I click on it to get to the addcontact page. Since I've added a login to my web app I cant seem to get the button to work. If I just have a link it does work. Any ideas how to get the button to work?

{% extends "base.html" %}

{% block content %}

  <h1>List of contacts</h1>
  <ul class=contacts>
 {% for contacts in contacts %}
   <li><h3><font face="verdana">
     <a href="{{ url_for('contact_detail',contact_id=contacts.id)}}">
     {{ contacts.surname }}, {{ contacts.firstname }}
     </a>
     </font>
   </h3></li>
 {% else %}
   <li><em>No contacts available</em></li>
 {% endfor %}
 </ul>
 <button type="button"><a class="box" href="/addcontact/">Add a new contact</a></button>

 {% endblock %}
Was it helpful?

Solution

Coincidentally, I also ran into this after adding login capabilities on my flask app, but I didn't investigate further, and I wouldn't think they would be related. It worked after I changed the button to a form with a submit button, where the form action is url_for('contact_add'), like this:

<form method="get" action="{{url_for('contact_add')}}">
    <input type="submit" value="Add a New Contact">
</form>

I didn't actually try running this, so I might have a syntax error or something.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top