0

I have a small "Hello World" Flask script that takes an output from a program, called rescuetime_api and puts it on a URL /blog. I wanted to run the script in Debug mode and hard-coded it into the top of my program but I was wondering if there is a way to pass this value through from my Bash shell. Thanks in advance for your help.

#Flask tutorial
import rescuetime_api as api
import os

from flask import Flask
app = Flask(__name__)

DEBUG = True

@app.route("/")
def hello():
    return "This is my homepage!"

@app.route("/blog")
def blog():
    result = api.download_rescuetime_json()[1][1]
    return "%s" % result

if __name__ == "__main__":
    if os.environ.get("FLASK_TUTORIAL_DEBUG"):
        DEBUG = True
    print "Running in debug:", DEBUG
    app.run(debug=DEBUG)

1 Answer 1

2

Your script already checks for the environment variable FLASK_TUTORIAL_DEBUG.

You could just set it in your shell, before executing the program:

export FLASK_TUTORIAL_DEBUG=1

and then run your program:

python myscript.py

And remember to unset the variable when you don't need it:

unset FLASK_TUTORIAL_DEBUG
Sign up to request clarification or add additional context in comments.

3 Comments

Would I run python script.py and then export FLASK_TUTORIAL_DEBUG=1 or would I want to export the variable before running the script?
You would need to export it before running the python script.
Or just FLASK_TUTORIAL_DEBUG=1 python myscript.py.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.