I am trying to change a variable called "sentence_count" according to user's input in a select form:
In my template, I have the following select:
<div class="form-group">
<h3>Length of summary (sentences):</h3>
<select name="length">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>
</div>
I then have a variable defined in gvar.py:
class Gvars:
def __init__(self):
self.sentence_count = 1
gvars = Gvars()
And use it (cross-file) in main.py:
def sum():
if request.method == 'POST':
select = request.form.get('articles')
gvars.sentence_count = request.form.get('length')
if select == "Guardian":
select = request.form.get('length')
if select == "1":
return render_template('guardian.html', sentence_count=request.form.get('length')),
if select == "2":
return render_template('guardian.html', sentence_count=request.form.get('length'))
if select == "3":
return render_template('guardian.html', sentence_count=request.form.get('length'))
return redirect(url_for("guardian"))
The variable 'sentence_count' is then used within the code to create a summary of that given length, the overall result is then under var 'summary' that appears in the template ('summary count' does not).
My question is how to make this work and how to change the sentence count variable according to the input. As for now, regardless of what the user choses in the select form, the length will always be the hardcoded '1'. I tried sentence_count = None in gvar.py, but that threw an error.
You can view the alpha app here to get an idea of the input, it takes a while to load and as you can see, there are no options for the length.
Thanks!
{{s3}}
`. Also for that reason I created a gvar class in gvar.py that I call cross-file anywhere: `class Gvars: def __init__(self): self.sentence_count = 1 gvars = Gvars()` – GOONhoon Sep 17 '21 at 02:32