Created
January 20, 2014 16:24
-
-
Save KenjiTakahashi/8523285 to your computer and use it in GitHub Desktop.
flask-jitsu, used backslashes, 'cause gist won't let me use proper ones
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
# Other Stuff | |
from lib import auth | |
app = Flask(__name__) | |
auth.init_app(app) | |
with app.app_context(): | |
auth.send_request('whatever') # Same instance as below, but different context. | |
@app.route('/') | |
def index(): | |
return auth.send_request('nothing') # Works always on the same instance of `auth`. | |
# Other Stuff |
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
from auth import Auth | |
auth = Auth() |
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
from random import randint | |
from flask import current_app | |
class Auth(object): | |
def __init__(self): | |
self.i = randint(0, 666) | |
def init_app(self, app): | |
self.api_key = app.config['API_PUBLIC'] | |
self.pri_key = app.config['API_PRIVATE'] | |
def send_request(self, *args, **kwargs): | |
# DO STUFF | |
print(self.i, current_app.app_context()) | |
################## OR | |
class Auth(object): | |
def __init__(self): | |
self.i = randint(0, 666) | |
def send_request(self, *args, **kwargs): | |
app = current_app | |
api_key = app.config['API_PUBLIC'] | |
pri_key = app.config['API_PRIVATE'] | |
# DO STUFF | |
print(self.i, current_app.app_context()) |
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
# Some Stuff | |
from lib import auth | |
@product_view.route('/products', methods=['GET']) | |
def prods_get(): | |
# Same instance of `auth` as in app.py, but different context. | |
auth.send_request('sth') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could also be solved by shaping directories structure like this: https://github.com/miguelgrinberg/microblog/tree/version-0.4.
But when you're stuck, you're stuck.