我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用flask_login.current_user.follow()。
def follow(username): """????""" user = User.query.filter_by(username=username).first() if user is None: return jsonify(error=constant.INVALID_USER) if user == current_user: return jsonify(constant.CANNOT_CON_MYSELF) if current_user.is_following(user): return jsonify(error=constant.ALREADY_CON) try: current_user.follow(user) except Exception as e: return jsonify(constant.FAIL) current_user.notify_follower(user.id, "follow_user") return jsonify(error="")
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('You are now following %s.' % username) return redirect(url_for('.user', username=username))
def follow(nickname): user = User.query.filter_by(nickname=nickname).first() if user is None: flash('??????') return redirect(url_for('user.index')) if current_user.is_following(user): flash('??????????') return redirect(url_for('user.users', nickname=nickname)) current_user.follow(user) flash('???? %s?' % nickname) return redirect(url_for('user.users', nickname=nickname)) # ????
def follows(nickname): user = User.query.filter_by(nickname=nickname).first() if user is None: flash('??????') return redirect(url_for('user.index')) page = request.args.get('page', 1, type=int) pagination = user.followers.paginate( page, per_page=current_app.config['FOLLOWERS_PER_PAGE'], error_out=False ) pagination2 = user.followed.paginate( page, per_page=current_app.config['FOLLOWERS_PER_PAGE'], error_out=False ) show_followed = False if current_user.is_authenticated: show_followed = bool(request.cookies.get('show_followed','')) if show_followed: follows = [{'user': i.follower, 'timestamp': i.timestamp} for i in pagination.items] else: follows = [{'user': i.followed, 'timestamp': i.timestamp} for i in pagination2.items] return render_template('user/follow.html', user=user, title='??', show_followed=show_followed, pagination=pagination, Permission=Permission, follows=follows) # ??cookies
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) db.session.commit() flash('You are now following %s.' % username) return redirect(url_for('.user', username=username))
def follow(username): user= User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('You are now following %s.' % username) return redirect(url_for('.user', username=username))
def follow(username): user=User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('You are now following %s.' % username) return redirect(url_for('.user', username=username))
def follow_or_unfollow(username): """ follow_or_unfollow user the request will sent with ajax example returned json: status: either "good" or "error" follow: if user follow the user follow = True else follow = None msg: if there is alert msg="some alert" else msg=None category: category of the msg (warning, primary, success) """ msg = None category = None follow = False user = User.query.filter_by(name=username).first_or_404() if not current_user.is_authenticated: status = "error" msg = "Please Login or signup first" category = "warning" elif not current_user.confirmed: status = "error" msg = "Please confirm your email first" category = "warning" else: status = "good" if not current_user.is_following(user): follow = True current_user.follow(user) elif current_user.is_following(user): current_user.unfollow(user) db.session.add(current_user) db.session.commit() return jsonify({"status": status, "msg": msg, "category": category, "follow": follow })
def topic(): """????, ???????""" topics = current_user.follow_topics.filter_by().all() # ??????????? topic_id = request.args.get("topic") # ????????id topic_selete = None # ????????None if topics: if topic_id: for topic in topics: if topic.topic.id == int(topic_id): topic_selete = topic.topic break if not topic_selete: topic_selete = topics[0].topic if topic_id: flash(constant.NOFOUND) return render_template("topic.html", base64=base64, user=current_user, topics=topics, topic_selete=topic_selete) # @main.route('/topics_search', methods=['POST']) # @login_required # def topics_search(): # """??????????????""" # cate = request.form.get("topic_cate", None) # topic_cate = TopicCategory.query.filter_by( # category_name=cate).first() # if topic_cate: # # ???json????????: # # ```topic_name:????
topic_desc:????
id:????
follow or unfollow
#
```
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('You are now following {}'.format(username)) return redirect(url_for('.user', username=username))
def unfollow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if not current_user.is_following(user): flash('You are not already following this user.') return redirect(url_for('.user', username=username)) current_user.follow(user) flash('You are not following {} anymore.'.format(username)) return redirect(url_for('.user', username=username))
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user.') return redirect('.user', username=username) current_user.follow(user) flash('You are now following %s.' %username) return redirect(url_for('.user', username=username))
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash(u'????') return redirect(url_for('.index')) if current_user.is_following(user): flash(u'?????????') return redirect(url_for('.user', username=username)) current_user.follow(user) flash(u'???? %s.' % username) return redirect(url_for('.user', username=username))
def follow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user') return redirect(url_for('.index')) if current_user.is_following(user): flash('You are already following this user') return redirect(url_for('.user',username=username)) current_user.follow(user) flash('You are now following %s' %username ) return redirect(url_for('.user',username=username)) #??????