标签:pytho 分支语句 ati 提示 2.4 基本 tab target err
Flask是一种使用Python 编写的轻量级Web应用框架, 实现了基础的核心, 用extension增加其他功能
它的WSGI工具箱采用Werkzeug, 模板引擎则使用Jinja2
from flask import Flask app = Flask(__name__) @app.route("/url") def handle_url: return "Something"
from flask import url_for url_for()
from flask import redirect redicrect()
from flask import request from flask import make_response // 设置Cookie response = make_response(url_for(‘index‘)) response.set_cookie(name, json.dumps(dict)) // 获取Cookie json.loads(request.cookies.get(name))
flask.render_template
{{ value }}
分支语句
{% if something %}
...
{% else %}
...
{% endif %}
循环语句
{% for object in objects %}
...
{% endif %}
// 基类: base.html
...
{% block content %}
{% endblock %}
...
// 子类: child.html
{% extends "base.html" %}
{% block content %}
...
{% endblock %}
from flask import flash // 注意: 使用前需要配置app.secret_key flash(strings) *.html {{ get_flashed_messages()[n] }}
@app.errorhandle(error_number)
from flask import abort abort(error_number)
jsonify用于返回json数据
用于执行外部脚本, 如连接数据库
flask_script.Manager
系统: Linux(CentOS)
WSGI服务器: Gunicorn, uWSGI, CherryPy, Tornado, Gevent, mod_wsgi(Apache)
Web服务器: Nginx
$ mkdir app $ cd app/ $ virtualenv flask New python executable in /home/user/app/flask/bin/python2 Also creating executable in /home/user/app/flask/bin/python Installing setuptools, pip, wheel...done. $ source flask/bin/activate (flask) $ (flask) $ deactivate
命令: supervisorctl
配置: /etc/supervisor/supervisor/conf.d/app.conf
DevOps, Fabric
Nginx配置
标签:pytho 分支语句 ati 提示 2.4 基本 tab target err
原文地址:http://www.cnblogs.com/hzl6255/p/6925100.html