如何将另一个python文件中的列表传递到我的瓶服务器?

2024-06-26 18:00:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力将一个列表从python文件传递到我的瓶服务器。我把它们分成函数,这样当你调用它时,它们就应该被打印出来

这就是我目前的情况:

from bottle import route, run, template, request
import sys
sys.path.append("../python")
from connectedDevices import *

@route('/list')
def print_list():
    # Functions taken from connectedDevices
    get_ip()
    get_mac()
    return template('Forum ID: {{get_ip()}})'), get_ip()=forum_id)

run(host='localhost', port=8080)

Tags: 文件函数runfromimportip服务器列表
1条回答
网友
1楼 · 发布于 2024-06-26 18:00:33

我设法解决了这个问题,显然如果我使用输入文件中的函数,我不能独立调用变量,只能调用函数lot。我删除了它们,现在我可以调用列表并使用:

@app.route('/')
def index():
    info={'iplist': iplist, 'maclist': maclist, 'signallist': signallist, 'hostlist': hostlist}
    tpl = '''
    <table>
    %for i in range(len(maclist)):
        IP Address: {{iplist[i]}}
    <br/>
        MAC Address: {{maclist[i]}}
    <br/>
        Signal: {{signallist[i]}}
    <br/>
        Hostname: {{hostlist[i]}}
    <br/>
    <br/>
    %end
    </table>
    '''
    return template(tpl, info)

相关问题 更多 >