@bp.route('/lixn/test101/<int:video_id>')这种路由只会匹配到/lixn/test101/1234,而不会匹配到/lixn/test101/first(亲测)方法中得到的video_id是int类型(亲测,为<type 'int'>)
@bp.route('/lixn/test101/<video_id>')会匹配到/lixn/test/101/first,lixn/test101/1234方法中得到的video_id是string类型(亲测,为<type 'unicode'>)
@bp.route('/lixn/test/visitor')
def lixn_test_v():
return get_topic_name(1234)
def get_topic_name(video, **kw):
if kw.get('ad_type') == 'vip':
return 'vip'
print '_'*100
print kw 为{}
print '-'*100
return 'happy'
不传**kw是一点问题没有的~
@bp.route('/lixn/test/visitor')
def lixn_test_v():
v = App.local.player
return 'xxxxxxxxxxxxxxx'
App.local.player是<obj.player.StaffOB object at 0x7f81e846aad0>, 是<class 'obj.player.StaffOB'>类型,
在node工程中没有,因为node要做前后端分离,所以没给配
@bp.route('/lixn/test')
def v1_lixn_test():
ops = F.get_api_ops(request.args)
if 'live_seq' not in request.args and 'video_seq' not in request.args:
return 'xxxxxxxx'
return 'yyyyyyy'
if里面可以这么搞~
class TestClass(object):
def __init__(self):
self.video = 1
self.page = 2
self.kw = 'dddd'
self.video_name = 'sssssssss'
self.show_play_count = 1
@bp.route('/lixn/test/test', methods=['GET', 'POST'])
def lixn_test1():
t = TestClass()
print t.__dict__.items()
return 'yyyyyyyy'
对象.__dict__.items()会访问到对象的所有属性
print出的结果[('kw', 'dddd'), ('show_play_count', 1), ('video', 1), ('page', 2), ('video_name', 'sssssssss')]t.__dict__返回{'kw': 'dddd', 'show_play_count': 1, 'video': 1, 'page': 2, 'video_name': 'sssssssss'}
t.__dict__()报错TypeError: 'dict' object is not callable
表类的.data,比如load出的对象的.data方法,g.page.data