Flask 4 拓展
NOTE
1.Flask被设计为可拓展模式,所以没有提供如数据库和用户认证等重要的功能,允许开发者按需开发。
2.使用Flask-Script支持命令行选项:
安装flask-script:
pip install flask-script
将命令行解析功能添加到hello.py程序:
#!/usr/bin/env python
from flask import Flask
from flask.ext.script import Manager
app = Flask(__name__)
manager = Manager(app)
@app.route('/')
def index():
return '<h1> Make P4 Great Again! </h1>'
if __name__ == '__main__':
# app.run(debug=True)
manager.run()
(venv) sh-3.2# ./hello_mng.py
./hello_mng.py:4: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
from flask.ext.script import Manager
usage: hello_mng.py [-?] {shell,runserver} ...
positional arguments:
{shell,runserver}
shell Runs a Python shell inside Flask application context.
runserver Runs the Flask development server i.e. app.run()
optional arguments:
-?, --help show this help message and exit
(venv) sh-3.2# ./hello_mng.py runserver -?
./hello_mng.py:4: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
from flask.ext.script import Manager
usage: hello_mng.py runserver [-?] [-h HOST] [-p PORT] [--threaded]
[--processes PROCESSES] [--passthrough-errors]
[-d] [-D] [-r] [-R]
Runs the Flask development server i.e. app.run()
optional arguments:
-?, --help show this help message and exit
-h HOST, --host HOST
-p PORT, --port PORT
--threaded
--processes PROCESSES
--passthrough-errors
-d, --debug enable the Werkzeug debugger (DO NOT use in production
code)
-D, --no-debug disable the Werkzeug debugger
-r, --reload monitor Python files for changes (not 100{'const':
True, 'help': 'monitor Python files for changes (not
100% safe for production use)', 'option_strings':
['-r', '--reload'], 'dest': 'use_reloader',
'required': False, 'nargs': 0, 'choices': None,
'default': None, 'prog': 'hello_mng.py runserver',
'container': <argparse._ArgumentGroup object at
0x10c0f4b50>, 'type': None, 'metavar': None}afe for
production use)
-R, --no-reload do not monitor Python files for changes
3.在默认情况下,Flask开发服务器监听localhost上的连接,所以只接收来自服务器本身所在计算机的连接。--host参数可以帮助web服务器知晓在哪个网络接口上监听。
(venv) sh-3.2# ./hello_mng.py runserver --host 0.0.0.0
./hello_mng.py:4: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead.
from flask.ext.script import Manager
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
你可以在公网IP的5000端口上进行请求。
2017/2/17
Flask 4 拓展的更多相关文章
- Flask解析(二):Flask-Sqlalchemy与多线程、多进程
Sqlalchemy flask-sqlalchemy的session是线程安全的,但在多进程环境下,要确保派生子进程时,父进程不存在任何的数据库连接,可以通过调用db.get_engine(app= ...
- 实验5、Flask设计模式和Web服务体验
1. 实验内容 Flask appbuilder包括基本的表单验证,内置管理模块.本节主要学习Flask appbuilder的后台管理模块使用和对Flask设计模式拓展作简要介绍 2. 实验要点 掌 ...
- 【Python】 SQLAlchemy的初步使用
SQLAlchemy 在很多Python的web框架中都整合进了SQLAlchemy这个主要发挥ORM作用的模块.所谓ORM,就是把复杂的SQL语句给包装成更加面向对象,易于理解的样子.在操作数据库的 ...
- FlaskWeb开发从入门到放弃(二)
第5章 章节五 01 内容概要 02 内容回顾 03 面向对象相关补充:metaclass(一) 04 面向对象相关补充:metaclass(二) 05 WTforms实例化流程分析(一) 06 WT ...
- 《Python全栈开发指南》第3版 Alex著(LFXC2018)
第一章 Python基础——Python介绍&循环语句 1.1 编程语言介绍 1.2 Python介绍 1.3 Python安装 1.4 第一个Python程序 1.5 变量 1.6 程序交互 ...
- 从Flask-Script迁移到Flask-Cli
Abstrct flask从0.11版本开始引入了click提供命令行支持,在此之前我们通常会引入Flask-Script来提供. 在<Flask web开发>这本书编写时flask0.1 ...
- 实验6、Flask API使用示例和拓展
实验介绍 1. 实验内容 Flask 提供了多种API拓展,本节我们主要学习基于RESTful的Flask应用程序设计 2. 实验要点 学习和掌握多种RESTful的设计模式 3.实验环境 Cento ...
- Python Flask构建可拓展的RESTful API
1-1 Flask VS Django 1-2 课程更新维护说明: 1-3 环境.开发环境与Flask: 1.3.1 关注版本更新说明: 1-4 初始化项目:
- [python][flask][flask-SQLAlchemy]关于flask-SQLAlchemy的初级使用教程
鉴于网上关于flask-SQLAlchemy的实例使用教程参差不齐,于此写下工作学习过程中的使用过程,以便分享交流. 对于python关于flask有一定了解的高端玩家来说,请转至flask官方开发文 ...
随机推荐
- poj3734 Blocks[矩阵优化dp or 组合数学]
Blocks Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6578 Accepted: 3171 Descriptio ...
- Android Thread Handler UIHandler demos
extends:http://blog.csdn.net/superjunjin/article/details/7540064 序效果:为了显示如何用message传值的简单例子 例1,点击按钮,持 ...
- windows MySQL5.7.9免安装版配置方法
1. 解压MySQL压缩包 将下载的MySQL压缩包解压到自定义目录下,我的解压目录是: "D:\Program Files\mysql-5.7.9-win32" ...
- js封装正则验证
//根据不同的验证内容,返回相应的正则表达式 function returnRegString(regName) { if (regName == "email") { retur ...
- pta 习题集 5-15 数组循环左移
本题要求实现一个对数组进行循环左移的简单函数:一个数组aa中存有nn(>0>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向左移mm(≥0≥0)个位置,即将aa中的数据由(a0a ...
- tomcat的server.xml中的Context节配置
Tomcat的默认网站目录是:C:\Tomcat 9.0\webapps\ROOT,里面的index.jsp,就是tomcat官方提供的默认页,如果按照默认配置,访问链接应当是http://local ...
- leetcode之Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- Python开发【笔记】:concurrent.futures 平行运算
平行运算 前言: 编写Python程序时,我们可能会遭遇性能问题,即使优化了代码,程序也依然有可能运行的很慢,从而无法满足我们对执行速度的要求,目前的计算机,其cpu核心数越来越多,于是,我们可以考虑 ...
- pandas 从txt读取DataFrame&DataFrame格式化保存到txt
前提 首先保证你txt里的文本内容是有规律可循的(例如,列与列之间通过“\t”.“,”等指定的可识别分隔符分隔): 例如我需要读取的数据,(\t)分隔: (此文件内容是直接以DataFrame格式化写 ...
- 双舵轮AGV里程计、运动控制核心算法
舵轮AGV可以通过调整两个舵轮的角度及速度,可以使小车在不转动车头的情况下实现变道,转向等动作,甚至可以实现沿任意点为半径的转弯运动,有很强的灵活性. 因此在AGV行业,这种驱动方式应用很广,但是目前 ...