Я думаю, вам нужны данные асинхронно, поэтому нужно использовать javascript. если вы последуете за мной -
измененная часть вашего html -
<ul id='dropdown1' class='dropdown-content'>
<li><a name="device" method="GET" SelectDevice="/">
<!-- added an id (submitButton) to call function in javascript -->
<li><a id="submitButton" inputmode="submit" value="{{mydevices[0]}}" selected>{{mydevices[0]}}</a></li>
</ul>
Используйте javascript fetch api для отправки почтового запроса на flask:
const button = document.getElementById('submitButton');
button.onClick = function(){
chosendevice = // its your responsibility to bring the device name here as string
fetch(`${window.origin}/device_statistics`, {
method: "POST",
credentials: "include",
cache: "no-cache",
body: chosendevice,
}).then(res => {
// here response comes (not your question primarily)
if(res.status !== 200) return;
res.text().then(data =>
// do whatever
});
}).catch(e => {
console.log(e);
});
}
ваш flask бэкэнд:
@app.route('/device_statistics', methods=['POST', 'GET'])
def device_stats():
mydevices = ['Hall', 'Door101', 'Door102', 'Garage' , 'Fiat 500','Audi A3']
if request.method == 'POST':
chosendevice = request.get_data().decode('utf-8')
print(chosendevice)
# do whatever with chosendevice
return 'whatever'
return render_template('device_statistics.html', mydevices=mydevices, error=error)