概述
wehello是flasklet的一个示例程序,它包含flasklet运行所需要的包、模块、配置文件、以及使用手册。请用下面命令获取它的源代码:
git clone ssh://dev@quanklife.com:5010/opt/codes/52go
cd 52go/wehello
wehello的文件结构如下:
*wehello*
*static*
*manual.html* *使用手册*
*__init__.py* *模块定义*
*flasklet.conf* *配置文件*
*hello.py* *实现hello world*
*manual.py* *显示使用手册*
环境变量
因为需要使用到各种资源文件,所以,在运行wehello之前,需要设置一下PYTHONPATH环境变量。
在WINDOWS下,如果你的52go全路径为:d:\52go,那么添加如下环境变量:
set PYTHONPATH= d:\52go
在linux下,如果你的52go全路径为:/opt/52go,那么添加如下环境变量:
export PYTHONPATH= /opt/52go
运行
在windows,运行如下命令:
python -m flasklet.flasklet -C d:\52go\wehello\flasklet.conf
在linux下,运行如下命令:
python -m flasklet.flasklet -C /opt/52go/wehello/flasklet.conf
测试
[http://quanklife.com/wehello/hellowold](http://quanklife.com/wehello/hellowold)
配置文件
[server]
host=0.0.0.0
port=80
[route]
static_url_path=/wehello/static
static_folder=d:/tietiehui/52go/wehello/static
template_folder=d:/tietiehui/52go/wehello/templates
home_page=index.html
[module]
hello=wehello.hello
[app]
rest_root_url=/wehello
[logging]
level=DEBUG
其中:
host:主机名或IP
port:监听端口
static_url_path:静态文件的URL路径
static_folder:静态文件的目录
template_folder:模板文件目录
home_page:首页
[module]中,可以增加任意的python模块,这些python模块必须实现init_flask_app函数,如wehello.hello。
[app]中,传递一些参数配置,本例中,使用rest_root_url参数来传递wehello的根路径。
level为日志的级别,可以是DEBUG,INFO,WARNING,CRITICAL之一。
网友评论