summaryrefslogtreecommitdiff
path: root/examples-for-debugging/Flask_test
diff options
context:
space:
mode:
Diffstat (limited to 'examples-for-debugging/Flask_test')
-rw-r--r--examples-for-debugging/Flask_test/blueprint_test.py21
-rwxr-xr-xexamples-for-debugging/Flask_test/pbserver.py40
-rw-r--r--examples-for-debugging/Flask_test/test.py46
-rw-r--r--examples-for-debugging/Flask_test/test2.py1
4 files changed, 108 insertions, 0 deletions
diff --git a/examples-for-debugging/Flask_test/blueprint_test.py b/examples-for-debugging/Flask_test/blueprint_test.py
new file mode 100644
index 0000000..2e7c31d
--- /dev/null
+++ b/examples-for-debugging/Flask_test/blueprint_test.py
@@ -0,0 +1,21 @@
+from flask import Blueprint, abort, jsonify
+simple_page = Blueprint('simple_page', __name__)
+@simple_page.route('/homies')
+def show():
+ return "what's up";
+
+@simple_page.route('/nope')
+def nope():
+ return bad_request("oh hell no")
+
+def bad_request(message):
+ response = jsonify({'message': message})
+ response.status_code = 400
+ return response
+
+
+#@simple_page.errorhandler(500)
+#def custom400(error):
+# response = jsonify({'message': error.description['message']})
+# # etc.
+
diff --git a/examples-for-debugging/Flask_test/pbserver.py b/examples-for-debugging/Flask_test/pbserver.py
new file mode 100755
index 0000000..400883a
--- /dev/null
+++ b/examples-for-debugging/Flask_test/pbserver.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python2.7
+
+#static routes
+#{{{
+@route('/im/<filename>')
+def server_static(filename):
+ return static_file(filename, root='frontend/im/')
+@route('/im')
+def server_static():
+ return static_file("index.html", root='frontend/im/')
+@route('/imgrid')
+def server_static():
+ return static_file("index.html", root='frontend/imgrid/')
+@route('/imgradient')
+def server_static():
+ return static_file("index.html", root='frontend/imgradient/')
+@route('/imlandscape')
+def server_static():
+ return static_file("index.html", root='frontend/imlandscape/')
+@route('/impattern')
+def server_static():
+ return static_file("index.html", root='frontend/impattern/')
+@route('/imbreak')
+def server_static():
+ return static_file("index.html", root='frontend/imbreak/')
+@route('/')
+def server_static():
+ return static_file("index.html", root='frontend/im/')
+@route('/css/<filename>')
+def server_static(filename):
+ return static_file(filename, root='frontend/css/')
+@route('/js/<filename>')
+def server_static(filename):
+ return static_file(filename, root='frontend/js/')
+@route('/img/<filename>')
+def server_static(filename):
+ return static_file(filename, root='frontend/img/')
+#}}}
+
+#run(host='0.0.0.0', port=8999, debug=True)
diff --git a/examples-for-debugging/Flask_test/test.py b/examples-for-debugging/Flask_test/test.py
new file mode 100644
index 0000000..b383b0d
--- /dev/null
+++ b/examples-for-debugging/Flask_test/test.py
@@ -0,0 +1,46 @@
+import simplejson as json
+from flask import Flask
+from flask import abort, redirect, url_for
+from blueprint_test import simple_page
+app = Flask(__name__)
+app.register_blueprint(simple_page)
+#app.logger.debug('A value for debugging')
+#app.logger.warning('A warning occurred (%d apples)', 42)
+#app.logger.error('An error occurred')
+
+@app.route("/")
+def hello():
+ return "Hello World!"
+
+if __name__ == "__main__":
+ app.run()
+
+@app.route('/login', methods=['POST', 'GET'])
+def login():
+ error = None
+ if request.method == 'POST':
+ if valid_login(request.form['username'],
+ request.form['password']):
+ return log_the_user_in(request.form['username'])
+ else:
+ error = 'Invalid username/password'
+ #searchword = request.args.get('key', '')
+ # the code below is executed if the request method
+ # was GET or the credentials were invalid
+ return render_template('login.html', error=error)
+
+
+
+@app.route('/')
+def index():
+ return redirect(url_for('login'))
+
+@app.route('/login')
+def login():
+ abort(401)
+ this_is_never_executed()
+
+
+url_for('static', filename='style.css')
+
+
diff --git a/examples-for-debugging/Flask_test/test2.py b/examples-for-debugging/Flask_test/test2.py
new file mode 100644
index 0000000..0a831b6
--- /dev/null
+++ b/examples-for-debugging/Flask_test/test2.py
@@ -0,0 +1 @@
+print __name__