是否可以更改 HUG for python 的端口号?我有以下我正在尝试做的示例。API 默认为端口 8000,但我希望能够手动设置它。
@hug.post()
def receive_json(request):
request=str(request)
print("Hello! Glad you're here!")
print(request)
process=os.system("echo "+'"'+request+'"')
是否可以更改 HUG for python 的端口号?我有以下我正在尝试做的示例。API 默认为端口 8000,但我希望能够手动设置它。
@hug.post()
def receive_json(request):
request=str(request)
print("Hello! Glad you're here!")
print(request)
process=os.system("echo "+'"'+request+'"')
在您的app.py
(或任何名称)文件的末尾添加:
hug.API(__name__).http.serve(port=8005)
用于在端口8005上服务
如果您使用hug
命令行脚本来启动您的应用程序,该-p / --port
选项将使您到达那里,如hug --port 5000 -f app.py
:
$ hug --help
usage: hug [-h] [-v] [-f FILE] [-m MODULE] [-p PORT] [-n] [-ma] [-i INTERVAL]
[-c COMMAND]
Hug API Development Server
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-f FILE, --file FILE file
-m MODULE, --module MODULE
module
-p PORT, --port PORT A Whole number
-n, --no_404_documentation
Providing any value will set this to true
-ma, --manual_reload Providing any value will set this to true
-i INTERVAL, --interval INTERVAL
A Whole number
-c COMMAND, --command COMMAND
command
您可以使用 Gunicorn 服务于 hug 应用程序并使用 -b 标志绑定到不同的端口。
gunicorn --reload myapp:__hug_wsgi__ -b0.0.0.0:8008