I’m developing an application using Flask.
I want a quick, automated way to add and remove debug=True to the main function call:
Development:
app.run(debug=True)
Production:
app.run()
For security reasons, as I might expose private/sensitive information about the app if I leave debug mode on “in the wild”.
I was thinking of using sed or awk to automate this in a git hook (production version is kept in a bare remote repo that I push to), or including it in a shell script I am going to write to fire up uwsgi and some other “maintenance”-ey tasks that allow the app to be served up properly.
What do you think?
You probably should not be using
app.runin production (and you definitely don’t need it if you are using uwsgi). Instead, use one of the several deployment options discussed in the deployment section of Flask’s excellent documentation. (app.runsimply callswerkzeug.serving.run_simplewhich executes Python’s includedwsgirefserver.)That being said, the correct way to do this is not with a post-deploy edit to your source code but with a server-specific config file that changes your settings as @brandizzi pointed out in his answer.
You can do this in several different ways (Flask has documentation on this too – see Armin’s suggestions on configuring from files and handling the development-production switch):
Include both your development and your server’s configs in your repository. Use an environmental variable to switch between them:
Store your production configuration in a separate repository along with any other server-specific configurations you may need. Load the config if an environmental variable is set.