我需要python flask环境中的帮助我有一些html页面,在该页面中我从SQL数据库获取ip地址列表,列表中的ip地址是可单击的。 我需要的是能够点击某些IP,并能够在FLASK中的另一个功能中使用该IP
部分代码我的代码示例: HTML
<!DOCTYPE html>
<html>
{% extends "base.html" %}
{% block content %}
<body>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
function goPython(){
$.ajax({
url: "/clicked",
context: document.body
}).done(function() {
alert('finished python script');;
});
}
</script>
{% for Devices in ip %}
<form action = "http://192.168.1.1:8081/clicked" method = "post">
<ul id="Devicesid">
<li class="label even-row">
<a onclick="goPython()" value="btnSend"><button type="button" name="btnSend">{{ Devices.ip }}</button></</a>
</li>
</ul>
</form>
</body>
{% endfor %}
</html>
{% endblock %}
和python main.py代码的一部分:
@main.route('/clicked',methods = ['POST', 'GET'])
def clicked():
while True:
IP = request.form['btnSend']
URL = 'https://' + IP
credentials = {'username': 'apiuser', 'secretkey': 'f00D$'}
session = requests.session()
###and so on......
正如您在HTML iam中看到的,使用FOR循环并从我的数据库获取ip地址, 现在,我正试图拥有点击IP地址的能力,并在python FLASK的另一个功能中使用它来连接到实用设备
我怎样才能做到简单和正确? 正如我所理解的,为了让它工作,我需要使用AJAX或JQuery
请帮忙
在JS/HTML代码中尝试以下操作:
相关问题 更多 >
编程相关推荐