return redirect(url_for('profile', nickname=nickname)) db.session.add(u) db.session.commit() flash('You are now following ' + nickname + '!') return redirect(url_for('profile', nickname=nickname)) #boilerplate @app.route('/unfollow/<nickname>') @login_required def unfollow(nickname): user = User.query.filter_by(nickname=nickname).first() #current is the db object of the current logged in user current = User.query.filter_by(id=current_user.id).first() if user is None: flash('User %s not found.' % nickname) return redirect(url_for('discover')) if user.id == current_user.id: flash('You can\'t unfollow yourself!') return redirect(url_for('profile', nickname=nickname)) u = current.unfollow(user) if u is None: flash('You are not following ' + nickname + '.') return redirect(url_for('profile', nickname=nickname)) db.session.add(u) db.session.commit() flash('You have stopped following ' + nickname + '.') return redirect(url_for('profile', nickname=nickname)) if __name__ == '__main__': app.run()
from smh import app app.run(debug=True, threaded=True, port=5123)
from smh import app app.run(debug=True)
from smh import db from smh.models.models import * from datetime import datetime import os from smh import app now = datetime.utcnow() try: if User.query.filter_by(nickname="admin").first() != None: app.run(debug=True, threaded=True, port=5000) else: u = User(nickname="admin", password="******", created=now) q = Question(body="No further Questions.", timestamp=now, author=u) qotd = QOTD(qotd=1) db.session.add(q) db.session.add(qotd) db.session.add(u) db.session.commit() app.run(debug=True, threaded=True, port=5000) except: pass
db.session.commit() flash('You are now following ' + nickname + '!') return redirect(url_for('profile', nickname=nickname)) #boilerplate @app.route('/unfollow/<nickname>') @login_required def unfollow(nickname): user = User.query.filter_by(nickname=nickname).first() #current is the db object of the current logged in user current = User.query.filter_by(id=current_user.id).first() if user is None: flash('User %s not found.' % nickname) return redirect(url_for('discover')) if user.id == current_user.id: flash('You can\'t unfollow yourself!') return redirect(url_for('profile', nickname=nickname)) u = current.unfollow(user) if u is None: flash('You are not following ' + nickname + '.') return redirect(url_for('profile', nickname=nickname)) db.session.add(u) db.session.commit() flash('You have stopped following ' + nickname + '.') return redirect(url_for('profile', nickname=nickname)) if __name__ == '__main__': app.run()