First of all, apologize if this question may have been asked before. I am relatively new in web programming, especially using Flask and HTML. I've seen a similar question (with the answer) here, however, I still couldn't figure out how to get a checked checkbox from my HTML. Here is what I've done so far. So I have this html code:
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Prod To Mongo</label>
<div class="content">
<div class="left-content">
<h2 id="prod-left-h2">HOSTS</h2>
<form action="/" method="get">
<label><input type="checkbox" class="radio" name="mongodata" value="mongodata">mongodata</label>
<label><input type="checkbox" class="radio" name="host" value="1">assets-mongod</label>
<label><input type="checkbox" class="radio" name="host" value="1">memcached</label>
</form>
</div>
<div class="middle-content">
<h2 id="prod-left-h2">DBs</h2>
<label><input type="checkbox" class="radio" name="DBs" value="1">admin</label>
<label><input type="checkbox" class="radio" name="DBs" value="1">custsvc-mongod-</label>
</div>
<div class="right-content">
<h2 id=prod-left-h2>COLLECTIONS</h2>
{% for collection in collection_list %}
<label><input type="checkbox" class="radio" name="collection" value="1">{{ collection }}</label>
{% endfor %}
</div>
<div class="button-content">
<div class="get-collection-button">
<form action="/" method="post">
<button name="collection-button" value="get collections" type="submit" class="button"> get collections</button>
</form>
</div>
<div class="sync-data-button">
<form action="/" method="post">
<button name="sync-button" value="sync data" type="submit" class="button"> sync data</button>
</form>
</div>
</div>
</div>
</div>
The following is my app.py:
from flask import Flask, render_template, send_from_directory,request
import os
from os.path import abspath, dirname
from django.shortcuts import render_to_response, RequestContext
from flask import send_from_directory
app = Flask(__name__,template_folder='ds-dashboard/templates/',static_folder='ds-dashboard/static')
# app = Flask(__name__,static_url_path='')
collections = ["A","B","C","D","E"]
@app.route('/')
def home():
return render_template('home.html')
@app.route('/',methods=['GET', 'POST'])
def button_clicked():
if request.form.get('sync-button',None) == "sync data":
value = request.form.getlist("mongodata")
print value
return "test"
elif request.form.get('collection-button',None) == "get collections":
return render_template('home.html', collection_list = collections)
if __name__ == '__main__':
app.run(debug=True, port=5001)
When I print value, it returns None. Any suggestion or help would be really appreciated. Thank you
sync-buttoni can't see any thing related in yourhtmlcontent.formi think that's the problem.value