title: Flask HTML link query
body: <p>How do make each contact a link?</p>
  <p>I was thinking doing this:</p>
  <p><code>&lt;li&gt;&lt;h3&gt;&lt;a href{url_for('addcontact/contact_id&quot;{{e[1].encode(&quot;utf-8&quot;)}}, {{e[2].encode(&quot;utf-8&quot;)}}&quot; {contact_id}&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt;</code></p>
  <p>My html</p>
  <pre><code> &lt;html&gt;
      &lt;body&gt;
        &lt;h1&gt;List of contacts&lt;/h1&gt;
        &lt;ul class=contacts&gt;
    {% for e in contacts %}
      &lt;li&gt;&lt;h3&gt;&quot;{{e[1].encode(&quot;utf-8&quot;)}}, {{e[2].encode(&quot;utf-8&quot;)}}&quot;&gt;&lt;/h3&gt;&lt;/li&gt;
    {% else %}
      &lt;li&gt;&lt;em&gt;No contacts available&lt;/em&gt;&lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
    &lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;
    &lt;a href=&quot;/addcontact/&quot;&gt;Add a contact&lt;/a&gt;
  </code></pre>
    
  
  <p>My Methods:
  contacts method</p>
  <pre><code> @app.route('/contacts/', methods=['GET','POST'])
      def contact_list():
         cur = g.db.execute('select contact_id, surname, firstname from address order by surname')
         contacts = cur.fetchall()
         return render_template(&quot;contacts.html&quot;, contacts = contacts) #refer to template
  </code></pre>
  <p>Add contacts method:</p>
  <pre><code> @app.route('/addcontact/', methods=['GET','POST'])
      def contact_add():
        if request.method == 'POST':
            g.db.execute('insert into address (surname, firstname, email, mobile) values (?, ?, ?, ?)',[request.form['firstname'], request.form['surname'], request.form['email']
              , request.form['mobile']])
            g.db.commit()
            flash('New entry was successfully posted')
            return redirect(url_for('/contacts')) #redirect to the contacts page
        elif request.method != 'POST':
            return render_template('addcontact.html')
  </code></pre>
  <p>`
  Additional description
  Basically I want to show surname and firstname but pass contact_id when you click into the link and go into detail that contact.</p>
  <p>contact detail method:</p>
  <h1>detail of a contact</h1>
  <pre><code>@app.route('/contacts/&lt;int:contact_id&gt;', methods=['GET'])
  def contact_detail(contact_id):
      if request.method == 'GET':
          cur = g.db.execute('select surname, firstname, email, mobile\
                          from address where contact_id = ?', [contact_id])
          select = cur.fetchall()
          return render_template('modcontact.html', select=select, contact_id=contact_id)
  </code></pre>
  <p>detail contact template:</p>
  <pre><code>&lt;html&gt;
   &lt;body&gt;
       &lt;h1&gt;Detail of contact {{select[0]}}&lt;/h1&gt;
       &lt;form action='/addcontact/' method=&quot;post&quot;&gt;
      &lt;dl&gt;      
        &lt;dd&gt;&lt;input type=&quot;submit&quot; value=&quot;Modify Contact&quot;&gt;
          &lt;dd&gt;&lt;input type=&quot;submit&quot; value=&quot;Delete Contact&quot;&gt;      
      &lt;/dl&gt;
       &lt;/form&gt;
       &lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;
       &lt;a href=&quot;/contacts&quot;&gt;List of contacts&lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>