Last active
May 1, 2017 21:09
-
-
Save arkenidar/fc65b0ca646a3c9427d51815ff88b59b to your computer and use it in GitHub Desktop.
Flask's "Application Context" test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from flask import Flask, current_app | |
app = Flask(__name__) | |
app_ctx = app.app_context() | |
with app_ctx: | |
print(current_app.name) | |
current_app.paths=[] | |
def path_add(path): | |
app_ctx = app.app_context() | |
with app_ctx: | |
current_app.paths+=[path] | |
def path_list(): | |
app_ctx = app.app_context() | |
with app_ctx: | |
return str(current_app.paths) | |
def page_content(): | |
html=''' | |
<a href=/a>a</a> <a href=/b>b</a> <a href=/c>c</a> | |
''' | |
return html+path_list() | |
@app.route('/') | |
def index(): | |
return page_content() | |
@app.route('/a') | |
def route_a(): | |
path_add('a') | |
return page_content() | |
@app.route('/b') | |
def route_b(): | |
path_add('b') | |
return page_content() | |
@app.route('/c') | |
def route_c(): | |
path_add('c') | |
return page_content() | |
if __name__=='__main__': | |
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SETUP: sudo apt-get install uwsgi uwsgi-plugin-python3 | |
# RUN: uwsgi --ini uwsgi_conf.ini | |
[uwsgi] | |
plugins = python3 | |
#logto = log.txt | |
# Tell uWSGI to run from a certain directory. | |
#chdir=flask_test | |
# Listen on port 5001 | |
http-socket=:5001 | |
# The Python module that contains an application object to deploy | |
module=flask_app_ctx:app | |
# The WSGI supported application object | |
callable=app | |
# How many threads to spawn per process | |
threads=15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment