P
P
pcdesign2017-09-20 11:45:29
Flask
pcdesign, 2017-09-20 11:45:29

How to put functions in a separate file?

I understand that it is possible to make a helper.py file

# helper.py
def bar():
    return 'Hi'

And calmly call in app.py
from helper import bar

@app.route("/")
def index():
    bar = bar()

But what to do when you need to put a function like this in a separate file:
get trans(key):
    return  redis_store.get('en_transcr:' + key)

Where
redis_store = FlaskRedis(app)
How in this case to take out such functions in a separate file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2017-09-20
@leahch

from Flask as flask

get trans(key):
    redis_store  = flask.g.redis
    return  redis_store.get('en_transcr:' + key)

PS. This is if the extension registers itself in app_context (), in the case of a radish - it registers.
You can also use
Almost the same thing, but you can put it there yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question