[Answered ]-SECRET_KEY error with Django using uWSGI

2๐Ÿ‘

โœ…

you cannot really do that as your environment is setup in ~/.bashrc locally which uwsgi does not have access to.

you might be able to get away with putting the variable in /etc/rc.local but Im not even sure that will work

you can add them to your file

[uwsgi]
chdir = /home/ubuntu/my_app
module = my_app.wsgi
# path below is to virtual environment
home = /home/ubuntu/my_app/env 
http = :8000
check-static = /var/www/my_app
daemonize = /var/log/uwsgi/my_app

# process-related settings
master = true
processes = 10
vacuum = true

#environment
env=SECRET_KEY="My Super Secret Key"

or you can configure it directly on the app object in your python file

app = Flask(__name__)
app.secret_key="My Super Secret Key"

which to be frank is probably the way I would do it

๐Ÿ‘คJoran Beasley

0๐Ÿ‘

inside your uwsgi ini config:

env = SECRETKEY=$(SECRETKEY)

^^^ this will instruct uwsgi to take the SECRETKEY env var and ensure it is set in the forked processes it creates

๐Ÿ‘คnachonachoman

Leave a comment