title: How to set a variable with pressing a button on an html file to the flask server route
body: <p>I've become a bit confused in the middle of this, hope you can help me,</p>
  
  <p>I have a text file similar to the one below:</p>
  
  <pre><code>./Video/SetUp
  ./Video/NewRecordings
  ./Video/NewRecordings/20160113_151920
  ./Video/Back Up
  ./Video/Back Up/FirstLecDraft
  ./Video/Back Up/FirstTalk
  </code></pre>
  
  <p>I use the python script below (thanks to <a href="https://github.com/Knio/dominate" rel="nofollow">Dominate</a>) to populate a html file using the <code>List</code> text file mentioned above:</p>
  
  <pre><code>import dominate
  from dominate.tags import *
  
  doc = dominate.document(title='Dominate your HTML')
  
  with doc.head:
      link(rel='stylesheet', href='style.css')
      script(type='text/javascript', src='script.js')
  
  with doc:
      with div():
          with open('List') as f:
              for line in f:
                  li(input(line.title(), type='submit', value='%s' % line,     onclick='self.location.href=\'http://127.0.0.1:5000/{This must be the same as "value" part}\''))
  
      with div():
          attr(cls='body')
  
  print doc
  </code></pre>
  
  <p>First question: How to pass the value of the <code>value</code> field to the rest of the path on <code>onclick</code>?</p>
  
  <p>The result must be something like this:</p>
  
  <pre><code>&lt;input href="" onclick="self.location.href='http://127.0.0.1:5000/cameradump/2016-01-21" type="submit" value="./cameradump/2016-01-21"&gt;
  </code></pre>
  
  <p>and respectively another values for another buttons.</p>
  
  <p>as you can see, the rest of the onclick path after <code>:5000/</code>must be exactly the same as the <code>value</code> field.</p>
  
  <p>Second question: How can I pass this to the route on flasks' <code>main.py</code> file? (e.g when the user presses each button, the value of that button must be set to the route dynamically)</p>
  
  <p><code>main.py</code> is like this for now:</p>
  
  <pre><code>from flask import Flask, render_template
  import subprocess
  app = Flask(__name__)
  
  @app.route("/{value must be passed here}")
  def index():
      return render_template('index.html')
   ...
  </code></pre>
  
  <p>but it should be like below if the user presses the button <code>/cameradump/2016-01-21</code>:</p>
  
  <pre><code>...
  @app.route("/cameradump/2016-01-21")
  def index():
  return render_template('index.html')
  ...
  </code></pre>
  
  <p>or another value according to the button which was pressed.</p>