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通过websocket与js客户端通信示例分析

Python通过websocket与js客户端通信示例分析

具体的 websocket 介绍可见 http://zh.wikipedia.org/wiki/WebSocket  这里,介绍如何使用 Python 与前端 js 进行通信。...

python脚本实现统计日志文件中的ip访问次数代码分享

适用的日志格式: 106.45.185.214 - - [06/Aug/2014:07:38:59 +0800] "GET / HTTP/1.0" 200 10 "-" "-" 1...

python排序函数sort()与sorted()的区别

python 中sorted与sort有什么区别 sort(cmp=None, key=None, reverse=False) sorted(iterable, cmp=None, k...

python中的reduce内建函数使用方法指南

官方解释: Apply function of two arguments cumulatively to the items of iterable, from left to r...

python实现超简单的视频对象提取功能

python实现超简单的视频对象提取功能

视频对象提取 与其说是视频对象提取,不如说是视频颜色提取,因为其本质还是使用了OpenCV的HSV颜色物体检测。下面话不多说了,来一起看看详细的介绍吧。 HSV介绍 HSV分别代表,...