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

yipeiwu_com4年前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的私有公有属性(必看篇)

python中,类内方法外的变量叫属性,类内方法内的变量叫字段。他们的私有公有访问方法类似。 class C: __name="私有属性" def func(self):...

Python基于pygame实现的弹力球效果(附源码)

Python基于pygame实现的弹力球效果(附源码)

本文实例讲述了Python基于pygame实现的弹力球效果。分享给大家供大家参考,具体如下: 运行效果: 代码部分如下: #A bouncing ball import sys,...

python和c语言的主要区别总结

python和c语言的主要区别总结

Python可以说是目前最火的语言之一了,人工智能的兴起让Python一夜之间变得家喻户晓,Python号称目前最最简单易学的语言,现在有不少高校开始将Python作为大一新生的入门语言...

sublime text 3配置使用python操作方法

1、 在sublime text的官网下载,是适合自己系统的版本。官网地址:https://www.sublimetext.com/3 2、安装好后,在菜单栏打开:Preferences...

Python 冒泡,选择,插入排序使用实例

最近学习了python基础,写一下3大排序练练手: 复制代码 代码如下: ''' Created on 2013-8-23 @author: codegeek ''' //冒泡排序 de...