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 拓展的更多相关文章

  1. Flask解析(二):Flask-Sqlalchemy与多线程、多进程

    Sqlalchemy flask-sqlalchemy的session是线程安全的,但在多进程环境下,要确保派生子进程时,父进程不存在任何的数据库连接,可以通过调用db.get_engine(app= ...

  2. 实验5、Flask设计模式和Web服务体验

    1. 实验内容 Flask appbuilder包括基本的表单验证,内置管理模块.本节主要学习Flask appbuilder的后台管理模块使用和对Flask设计模式拓展作简要介绍 2. 实验要点 掌 ...

  3. 【Python】 SQLAlchemy的初步使用

    SQLAlchemy 在很多Python的web框架中都整合进了SQLAlchemy这个主要发挥ORM作用的模块.所谓ORM,就是把复杂的SQL语句给包装成更加面向对象,易于理解的样子.在操作数据库的 ...

  4. FlaskWeb开发从入门到放弃(二)

    第5章 章节五 01 内容概要 02 内容回顾 03 面向对象相关补充:metaclass(一) 04 面向对象相关补充:metaclass(二) 05 WTforms实例化流程分析(一) 06 WT ...

  5. 《Python全栈开发指南》第3版 Alex著(LFXC2018)

    第一章 Python基础——Python介绍&循环语句 1.1 编程语言介绍 1.2 Python介绍 1.3 Python安装 1.4 第一个Python程序 1.5 变量 1.6 程序交互 ...

  6. 从Flask-Script迁移到Flask-Cli

    Abstrct flask从0.11版本开始引入了click提供命令行支持,在此之前我们通常会引入Flask-Script来提供. 在<Flask web开发>这本书编写时flask0.1 ...

  7. 实验6、Flask API使用示例和拓展

    实验介绍 1. 实验内容 Flask 提供了多种API拓展,本节我们主要学习基于RESTful的Flask应用程序设计 2. 实验要点 学习和掌握多种RESTful的设计模式 3.实验环境 Cento ...

  8. Python Flask构建可拓展的RESTful API

    1-1 Flask VS Django 1-2  课程更新维护说明: 1-3 环境.开发环境与Flask: 1.3.1 关注版本更新说明: 1-4 初始化项目:

  9. [python][flask][flask-SQLAlchemy]关于flask-SQLAlchemy的初级使用教程

    鉴于网上关于flask-SQLAlchemy的实例使用教程参差不齐,于此写下工作学习过程中的使用过程,以便分享交流. 对于python关于flask有一定了解的高端玩家来说,请转至flask官方开发文 ...

随机推荐

  1. java GC工作机制

    转自:http://www.cnblogs.com/hzdtf/articles/5419987.html GC:垃圾回收站,是将java的无用的堆对象进行清理,释放内存,以免发生内存泄露.在介绍ja ...

  2. ionic+cordova开发!

    这里是一些学习的过程中纪录的: 官方网站: http://www.ionic-china.com/ 参考文章: https://blog.csdn.net/xyzz609/article/detail ...

  3. CH1809匹配统计【KMP】

    1809 匹配统计 0x18「基本数据结构」练习 描述 阿轩在纸上写了两个字符串,分别记为A和B.利用在数据结构与算法课上学到的知识,他很容易地求出了“字符串A从任意位置开始的后缀子串”与“字符串B” ...

  4. 利用maven-assembly-plugin加载不同环境所需的配置文件及使用场景

    背景: 如何加载不同环境的配置文件已经成了势在必行的,我们通常利用profile进行,详情参见我上篇博客 http://www.cnblogs.com/lianshan/p/7347890.html, ...

  5. docker基本操作命令

    1. 构建镜像 docker build -t centos/tomcat:7.0 2. 创建一个容器 docker run --name test-tomcat centos/tomcat:7.0 ...

  6. MySQL怎样存储IP地址 IP转数字 互转

    MySQL怎样存储IP地址 - cn三少 - 博客园 https://www.cnblogs.com/cnsanshao/p/3326648.html

  7. teamviewer and openconnect-gp (globalprotect) in ubuntu

    wget https://download.teamviewer.com/download/teamviewer_i386.deb sudo dpkg -i teamviewer_i386.deb a ...

  8. 设置webView头部不能滑动

    设置webView头部不能滑动 _webView.scrollView.bounces=NO;

  9. Django权限系统auth模块详解

    转自:原文出处 auth模块是Django提供的标准权限管理系统,可以提供用户身份认证, 用户组和权限管理. auth可以和admin模块配合使用, 快速建立网站的管理系统. 在INSTALLED_A ...

  10. django的request对象和response对象

    概述Django 使用 request 和 response 对象表示系统状态数据..当请求一个页面时,Django创建一个 HttpRequest 对象.该对象包含 request 的元数据. 然后 ...