我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用flask_login.current_user.unfollow()。
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 following this user.') return redirect(url_for('.user', username=username)) current_user.unfollow(user) flash('You are not following %s anymore.' % username) return redirect(url_for('.user', username=username))
def unfollow(nickname): user = User.query.filter_by(nickname=nickname).first() if user is None: flash('??????') return redirect(url_for('user.index')) if not current_user.is_following(user): flash('?????????????') return redirect(url_for('user.users', nickname=nickname)) current_user.unfollow(user) flash('?????? %s ?' % nickname) return redirect(url_for('user.users', nickname=nickname))
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 following this user.') return redirect(url_for('.user', username=username)) current_user.unfollow(user) db.session.commit() flash('You are not following %s anymore.' % 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 unfollow(username): """????""" user = User.query.filter_by(username=username).first() if user is None: return jsonify(error=constant.INVALID_USER) if not current_user.is_following(user): return jsonify(error=constant.NO_CON) try: current_user.unfollow(user) except Exception as e: return jsonify(constant.FAIL) return jsonify(error="")
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 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 following this user.') return redirect('.user', username=username) current_user.unfollow(user) flash('You are not following %s anymore.' %username) return redirect(url_for('.user', username=username))
def unfollow(username): user = User.query.filter_by(username=username).first() if user is None: flash(u'????') return redirect(url_for('.index')) if not current_user.is_following(user): flash(u'????????') return redirect(url_for('.user', username=username)) current_user.unfollow(user) flash(u'?????? %s' % 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 following this user') return redirect(url_for('.user',username=username)) current_user.unfollow(user) flash('You are not following %s anymore' %username) return redirect(url_for('.user',username=username)) #?????