语法错误Flask应用程序

2024-05-23 21:35:30 发布

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

我有以下代码:

t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))

它给了我一个错误:

File "/home/deploy/tgbot/tgbot.py", line 1170
t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))
                                                    ^

有什么问题吗?在


Tags: run代码apphosttargethomeport错误
1条回答
网友
1楼 · 发布于 2024-05-23 21:35:30

app.run的顺序参数可以在元组中传递(用括号构造,但没有名称)。命名参数必须在字典中传递。字典是用dict()或大括号而不是圆括号构造的。在

由于host和{}是app.run的前两个参数,因此以下任何一个都可以工作:

# positional args, passed as a tuple
t1 = threading.Thread(target=app.run, args=('0.0.0.0', 443))

# named args, passed in a dictionary created via dict()
t1 = threading.Thread(target=app.run, kwargs=dict(host='0.0.0.0', port=443))

# named args, passed in a dictionary created via {}
t1 = threading.Thread(target=app.run, kwargs={'host': '0.0.0.0', 'port': 443}))

相关问题 更多 >