def add(request): user = current_user(request) form = request.form() weibo = Weibo(form) weibo.user_id = user.id weibo.save() return redirect('/weibo/index?user_id={}'.format(user.id))
def add(request): form = request.json() u = current_user(request) w = Weibo(form) w.user_id = u.id w.save() # 把创建好的 weibo 返回给浏览器 return json_response(w.json())
def add(): form = request.form u = current_user() t = Weibo(form) t.user = u if t.valid(): t.save() return redirect(url_for('.index'))
def add(request): uid = current_user(request) user = User.find(uid) # 创建微博 form = request.form() w = Weibo(form) w.user_id = user.id w.save() return redirect('/weibo/index?user_id={}'.format(user.id))
def add(): form = request.form u = current_user() t = Weibo(form) t.name = u.username if t.valid(): t.save() # 蓝图中的 url_for 需要加上蓝图的名字,这里是 todo return redirect(url_for('.index'))
def add_weibo(): u = current_user() form = request.form w = Weibo(form) valid, message = w.valid() if valid: w.author_id = u.id w.save() return ajax_response(valid=valid, data=w.json(), message=message)
def add(): # 得到浏览器发送的表单,浏览器用 Ajax 发送 json 格式的数据过来 # 所以这里用新增加的 json 函数来获取格式化后的 json 数据 form = request.get_json() # 创建一个 weibo w = Weibo(form) u = current_user() w.user_id = u.id w.save() # 把创建好的 weibo 返回给浏览器 return jsonify(w.json())
def weibo_add(): #form = request.form print('weiboadd') form = request.get_json() print('form', form) w = Weibo(form) u = current_user() w.name = u.username print('form', form) if w.valid(): w.save() return api_response(True, data=w.json()) else: return api_response(False, message=w.error_message())
def test_tweet(): # 用户 1 发微博 form = {'content': 'hello tweet'} t = Weibo(form, 1) t.save() # 用户 2 评论微博 form = {'content': '楼主说得对'} c = Comment(form, 2) c.tweet_id = 1 c.save() # 取出微博 1 的所有评论 t = Weibo.find(1) print('comments, ', t.comments()) pass
def add(): u = current_user() if u is not None: # log('weibo add', u.id, u.username, u.password) form = request.form w = Weibo(form) w.username = u.username w.user_id = u.id if w.valid_add(): w.save() # log("save", w.user_id) return redirect(url_for('.index', username=u.username)) else: abort(401)
def add(request): """ 用于增加新 weibo 的路由函数 """ uname = current_user(request) u = User.find_by(username=uname) if u is None: return redirect('/login') if request.method == 'POST': # 'title=aaa' ==> {'title': 'aaa'} form = request.form() w = Weibo(form, u.id) w.save() return redirect('/weibo')
def add(): print('4455') form = request.form u = current_user() t = Weibo(form) t.name = u.username r = {'data': []} if t.valid(): t.save() r['success'] = True r['data'] = t.json() else: r['success'] = False message = t.error_message() r['message'] = message print('123321') return json.dumps(r, ensure_ascii=False)
def add(request): form = request.json() u = current_user(request) w = Weibo(form) w.user_id = u.id w.save() weibos = w.all_json() weibo_list = [] for i in range(len(weibos)): weibo_list.append( dict(id=weibos[i]['id'], content=weibos[i]['content'], user_id=weibos[i]['user_id'], weibo_user=User.find_by(id=weibos[i]['user_id']).username)) weibos = weibo_list[-1] # 把创建好的 weibo 返回给浏览器 return json_response(weibos)
def add(): print('api.py weibo add was called') form = request.form u = current_user() t = Weibo(form) t.name = u.username r = {'data': []} if t.valid(): t.save() print('api.weibo.add.r', r) print('api.weibo.add.t', t) r['success'] = True r['data'] = t.json() else: r['success'] = False message = t.error_message() r['message'] = message print('api.py weibo.add.response', r) return json.dumps(r, ensure_ascii=False)