【问题标题】:How can I pass a list from another python file to my bottle server?如何将列表从另一个 python 文件传递​​到我的瓶子服务器?
【发布时间】:2019-05-14 09:59:08
【问题描述】:

我正在努力将一个列表从 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)

【问题讨论】:

  • 也许是这个? return template('Forum ID: {{ip_list}})'), ip_list=get_ip())
  • 这段代码到底有什么问题?
  • @mkrieger1 它不打印函数get_ip()的内容
  • @mkrieger1 你试过我提出的解决方案了吗?

标签: python bottle


【解决方案1】:

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

@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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2020-04-25
    • 2018-01-08
    • 2015-12-07
    • 1970-01-01
    • 2013-08-17
    • 2014-02-12
    相关资源
    最近更新 更多