Problem
Flask app returns None
when an environmental variable os.environ.get()
is rendered in template mapboxgl.accessToken = {{ mapbox_access_token }}
.
Workfiles
Environmental variable is saved in ~/.bashrc: export MAPBOX_ACCESS_TOKEN='XXXXXXXX'
from flask import Flask, render_template
import os
app = Flask(__name__)
@app.route('/')
def hello_world():
access_token = os.environ.get('MAPBOX_ACCESS_TOKEN')
return render_template('index.html', mapbox_access_token=access_token)
if __name__ == '__main__':
app.run()
The error appears to be in this line access_token = os.environ.get('MAPBOX_ACCESS_TOKEN')
, as I tried replacing with access_token = XXXXXXXX
which renders fine. However, obviously I want to avoid hard-coding sensitive information to the file.