add_post(session, request.session.get('username'), post, link, preview) return redirect('/') @app.route('/post') @login_required @apply_csp def view_post(request): if request.method == 'GET': post_id = request.args.get('id') instance = request.args.get('instance') success, post = get_post(session, post_id, instance) if success: return render_template('post.html', post=post) else: return render_template('404.html') @app.route('/report') @apply_csp def report(request): #: neko checks for naughtiness #: neko likes links pass if __name__ == '__main__': app.run('0.0.0.0', port=5000)
if post_id.isdigit(): botuser("http://127.0.0.1", instance, post_id) return redirect('/') @app.route('/approve') @ensure_csrf @login_required @apply_csp def approve_follower(request): # TODO: Frontend support for the private acounts if request.method == 'GET': if not check_csrf(request): return redirect('/404') approver_username = request.session.get('username') follower_username = request.args.get('username') success, msg = add_follower(session, approver_username, follower_username) if success: return redirect('/') else: return redirect('/404') if __name__ == '__main__': app.run('0.0.0.0', port=80)
raise ImportError('This is not a module, but a script.') import sys, os, socket test_root = os.path.dirname(os.path.abspath(__file__)) os.chdir(test_root) sys.path.insert(0, os.path.dirname(test_root)) sys.path.insert(0, test_root) try: server = sys.argv[1] port = int(sys.argv[2]) if server == 'gevent': from gevent import monkey monkey.patch_all() from flagon import Flagon app = Flagon() @app.route('/test') def test(): return 'ok' app.run(host=server, port=port) except socket.error: sys.exit(3) except ImportError: sys.exit(128) except KeyboardInterrupt: pass
from flagon import Flagon, request app = Flagon('example1') @app.before_request def before_request(): if request.endpoint == 'hello_world': if 'foo' not in request.view_args: request.view_args.update(foo='123') if request.endpoint == 'hello_world2': if 'foo2' in request.view_args: request.view_args.pop('foo2') @app.route('/') @app.route('/<foo>/bar') def hello_world(foo): print 'hello', foo return 'Hello World!' @app.route('/<foo2>/noarg') def hello_world2(): return 'Hello World!' @app.route('/<int:number>/num') def hello_world3(number): return 'Hello World! %s'%(number) if __name__ == '__main__': app.run()