ããã«ã¡ãFlaskãã Pythonã®ãæ軽WAF
Djangoã¯ã¨ã¦ããããã¨ã¦ããããå°ããªãµã¼ãã¹ãä½ãã¨ãã«ã¯ã¡ãã£ã¨ã¡ã³ãã¯ãµã¤ãurls.pyã¿ãããªã®ã¯å¥ãã¡ã¤ã«ã«å¥ãã¦ããªãã¦ããããsettings.pyãæ¯ååããã¨æ¸ãã¦ãæ°ãããã大ããªãµã¤ããä»äºã§ãããªãããã®ããç¥ããªããã©å°ããªç©ããµãã¯ãªä½ããä½ãã¨ãã«ã¯ã¡ãã£ã¨å¤§å¤ã ã¨æããæãããã
ãã®ç¹Flaskã¯ãããã·ã³ãã«ã ãShellãæ¸ãã¦ãæ°åã§webAppãæ¸ããããã³ãã¬ã¼ãã使ããããurlsãå¥ã«æ¸ããªãã¦ãããï¼ãã³ã¬ã¼ã¿ã§æ¸ãã¦ããã®ã§è³è² è·ãå°ãªãã
Flaskã®ã¤ã³ã¹ãã¼ã«
sudo easy_install flask
åºæ¬çãªããã¨ã
ãã¥ã¼ããªã¢ã«ãé©å½ã«ã¾ã¨ãã¦ã¿ããä»å¾ã®èªåç¨ã«ã¡ã¢
flask_basic.py
#!/usr/bin/env python # coding:utf-8 from flask import Flask from flask import abort, redirect, url_for app = Flask(__name__) app.debug = True @app.route("/") def index(): return "root uri" @app.route('/hello') def hello(): return 'Hello World' @app.route('/str/<arg_str>') def show_arg(arg_str): app.logger.info('this is str %s'%arg_str) return '%s'%arg_str @app.route('/int/<int:arg_int>') def show_post(arg_int): return '%s'%arg_int @app.route('/redir') def redir(): return redirect(url_for('index')) if __name__ == "__main__": app.run(host='0.0.0.0', port=9090)
ãã°ã¤ã³ãã»ãã·ã§ã³ã«è¨é²
#!/usr/bin/env python # coding:utf-8 from flask import Flask, session, redirect, url_for, escape, request app = Flask(__name__) @app.route('/') def index(): if 'username' in session: return '''Logged in as %s<br> <a href='/logout'>logout</a>'''%escape(session['username']) return '''You are not logged in<br> <a href='/login'>login</a>''' @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': session['username'] = request.form['username'] return redirect(url_for('index')) return '''<form action="" method="post"> <p><input type=text name=username> <p><input type=submit value=Login> </form>''' @app.route('/logout') def logout(): # remove the username from the session if its there session.pop('username', None) return redirect(url_for('index')) # set the secret key. keep this really secret: app.secret_key = 'tekitouna himitu no kagi' if __name__ == "__main__": app.run(host='0.0.0.0', port=9090)
以ä¸
ããã¾ã§ã§ä¸çªç°¡åã§ååãªæ©è½ãããããå
¥ã£ã¦ãã
足ããªããã°
http://flask.pocoo.org/extensions/
http://flask.pocoo.org/snippets/
ãã¿ãã°wktkããæã