python flask web服务实现更换默认端口和IP的方法

yipeiwu_com6年前Python基础

flask web后台启动后会发现默认是 localhost 127.0.0.1:5000

如果需要修改,方便调试发布

可以采用以下方式运行

from flask import Flask
from flask import request
app = Flask(__name__)


@app.route('/')
def index():
 user_agent=request.headers.get('User_Agent')
 return 'user_agent is %s' %user_agent

if __name__ == '__main__':
 app.run(
  host='0.0.0.0',
  port= 5000,
  debug=True
 )

结果如下

Serving Flask app “start” (lazy loading)
Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
Debug mode: on
Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Restarting with stat
Debugger is active!
Debugger PIN: 807-167-541

以上这篇python flask web服务实现更换默认端口和IP的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python学习笔记之Zip和Enumerate用法实例分析

本文实例讲述了Python Zip和Enumerate用法。分享给大家供大家参考,具体如下: Python 中的 Zip zip的作用:可以在处理循环时用到,返回一个将多个可迭代对象组合...

Python实现图片拼接的代码

具体代码如下所示: import os from PIL import Image UNIT_SIZE = 220 # the size of image save_path = '...

Python的Urllib库的基本使用教程

Python的Urllib库的基本使用教程

1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由浏览器解释才呈现出来的,实质它 是一段HTML代码,...

Python3.5内置模块之os模块、sys模块、shutil模块用法实例分析

Python3.5内置模块之os模块、sys模块、shutil模块用法实例分析

本文实例讲述了Python3.5内置模块之os模块、sys模块、shutil模块用法。分享给大家供大家参考,具体如下: 1、os模块:提供对操作系统进行调用的接口 #!/usr/b...

pyqt5对用qt designer设计的窗体实现弹出子窗口的示例

1. 用qt designer编写主窗体,窗体类型是MainWindow,空白窗口上一个按钮。并转换成mainWindow.py # -*- coding: utf-8 -*- #...