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官方开发文 ...
随机推荐
- Windows Phone 在读取网络图片之前先显示默认图片
1.新建一个控件WindowsPhoneControl1 WindowsPhoneControl1.xaml <UserControl x:Class="DefaultImage.Wi ...
- log4net类库配置、WebService配置
一.类库配置 结构如下图 1.LogUtility类 public class LogUtility { private static readonly log4net.ILog log = log4 ...
- IE各浏览器HACK
border:2px solid #00f; /*IE.ff的属性*/ border:2px solid #090\9; /* IE6/7/8的属性 */ border:2px solid #F90\ ...
- Nexus介绍
转自:https://www.cnblogs.com/wincai/p/5599282.html 开始在使用Maven时,总是会听到nexus这个词,一会儿maven,一会儿nexus,当时很是困惑, ...
- [MongoDB] 安装MongoDB配置Replica Set
MongoDB的环境主要包括StandAlone,Replication和Sharding. StandAlone:单机环境,一般开发测试的时候用. Replication:主从结构,一个Primar ...
- 07.Curator计数器
这一篇文章我们将学习使用Curator来实现计数器.顾名思义,计数器是用来计数的,利用ZooKeeper可以实现一个集群共享的计数器.只要使用相同的path就可以得到最新的计数器值,这是由Zo ...
- 170622、springboot编程之JPA操作数据库
JPA操作数据库 什么事JAP?JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. 1.在pom ...
- CRM - 起步
一.crm简介 crm 客户关系管理软件 ( Customer Relationship Management ) 二.起步 models.py 表结构 from django.db import m ...
- python通过os.walk() 遍历出多级目录下所有文件绝对路径
代码如下 将遍历出来的路径全部添加到列表中: def get_all_abs_path(source_dir): path_list = [] for fpathe, dirs, fs in os.w ...
- 【Python】获取翻页之后的各页面中的属性值。
如何获取翻页之后的页面中的html标签中的属性值? # coding=utf-8 from selenium import webdriver if __name__=="__main__& ...