I have a total of two python scripts. One for the flask itself, and another for backend calculations. And I have an HTML file.
In backend.py:
def get_country():
county_name = ["Bangladesh", "India", "USA"]
country_default = "Bangladesh"
return country_name, country_default
In flask_app.py:
import backend
from flask import Flask
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
country_name, country_default = backend.get_country()
return render_template("index.html", country=county_name, default=country_default)
In index.html:
<form action="" class="form-text" method="GET">
<div class="row">
<div class="col-10">
<select name="select_country" class="form-select form-select-lg mb-3" aria-label=".form-select-lg example">
{% for country in country %}
<option value="{{country}}">{{country}}</option>
{% endfor %}
</select>
</div>
<div class="col-2">
<button type="submit" class="btn btn-outline-primary">Select</button>
</div>
</div>
</form>
<p>You have selected {{default}}</p>
The questions I have here are:
- How can I make the select tag in the HTML file to select the
default
value initially? - How can I submit the select tag value in the html file and update the
country_default
variable in the backend.py?