Jump to content

Help with environment (.env) setup with Python and Flask on Jonny


Recommended Posts

Posted

Hi, Thanks for setting all this up and taking the time to support all of us!

My questions is regarding properly setting up environmental variables for Flask. I have set up a sample (simplified) project to iron this issue out.  https://flask.dkobrin.helioho.st/MyNewFlaskApp/

I have looked through the discord for advice on this issue and have located my .env file in a non-public folder /home/environments/MyNewFlaskApp/.env and added the path to my load_dotenv (and for debugging dotenv_values), but although pathlib verifies the file exists, there are no key value pairs loaded. I set the permissions for the .env to 644 although I think it should be 640... 

here is the server

import sys

from flask import Flask, __version__
from dotenv import load_dotenv, dotenv_values
from os import environ as env

from getenv_path import env_path

# load environment vars
load_dotenv("/home/dkobrin.helioho.st/environment/MyNewFlaskApp/.env") #env_path)
config = dotenv_values("/home/dkobrin.helioho.st/environment/MyNewFlaskApp/.env") #env_path)
config2 = dotenv_values("/home/environment/MyNewFlaskApp/.env")
if env_path.exists:
  print(env_path)
  print('FOO is')
  print(env.get('FOO'))
  print(config)
  print(config2)

app = Flask(__name__)
application = app

@app.route("/")
def hello():
  if env_path.exists:
    print(env_path)
    print('FOO is')
    print(env.get('FOO'))
    print(config)
    print(config2)
  return """

    Flask is working on HelioHost.<br><br>
    <a href="/flasktest/python/version/">Python version</a><br>
    <a href="/flasktest/flask/version/">Flask version</a>

  """

@app.route("/python/version/")
def p_version():
  return "Python version %s<br><br><a href='/flasktest/'>back</a>" % sys.version

@app.route("/flask/version/")
def f_version():
  return "Flask version %s<br><br><a href='/flasktest/'>back</a>" % __version__

if __name__ == "__main__":
  app.run()

the sample base code does work so the .htaccess and flask.wsgi seem to be ok

here is my log output

image.thumb.png.69c5b5c84dbdc962ee3428ea6560442d.png

I feel like I'm missing something simple here.

Thanks again!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...