This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf8 | |
from flask_script import Manager | |
from flask import Flask, render_template | |
from flask import Response, json | |
app = Flask(__name__) | |
def list_jsonify(resp): | |
return Response(json.dumps(resp), mimetype='application/json') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [31]: url = 'http://www.baidu.com/a/b/c' | |
In [32]: d = dsnparse.parse(url) | |
In [33]: d | |
Out[33]: <dsnparse.ParseResult at 0x7f4a80fd99e8> | |
In [34]: d.path | |
Out[34]: '/a/b/c' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [31]: url = 'http://www.baidu.com/a/b/c' | |
In [32]: d = dsnparse.parse(url) | |
In [33]: d | |
Out[33]: <dsnparse.ParseResult at 0x7f4a80fd99e8> | |
In [34]: d.path | |
Out[34]: '/a/b/c' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def add(a, b): | |
return a + b | |
add(4, 2) | |
6 | |
plus3 = functools.partial(add, 3) | |
plus5 = functools.partial(add, 5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import Blueprint, render_template, abort | |
from jinja2 import TemplateNotFound | |
import flask | |
bp = flask.Blueprint('bp1', 'bp1', url_prefix='/bp1/<name>') | |
@bp.route('/users') | |
def filter_users(name): | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf8 | |
from flask_script import Manager | |
from flask import Flask, render_template | |
app = Flask(__name__) | |
@app.route("/user/<name>") | |
def hello_you(name): | |
return render_template('name.html', name=name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf8 | |
from flask_script import Manager | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/user/<name>") | |
def hello_you(name=None): | |
return "hello {name}".format(name=name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf8 | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/433") | |
def hello_433(): | |
return "hello ", 433 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_is_admin(f): | |
def wapper(*args, **kwargs): | |
if kwargs.get('username') != 'admin': | |
raise Exception('This user is not allowed to get') | |
return f(*args, **kwargs) | |
return wapper | |
class Store(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_functions = {} | |
def register(f): | |
global _functions | |
_functions[f.__name__] = f | |
return f | |
@register | |
def foo(): |
NewerOlder