Rather than using environmental variables to hide sensitive information, such as, SECRET_KEY, I'm using a module called local_settings.py
since the file is ignored by gitignore
.
Within settings.py
, I imported the module as from .local_settings import *
I'm using PythonAnywhere as the means of deploying my website yet when python manage.py collectstatic
is executed in its console the following error is raised:
from .local_settings import *
ModuleNotFoundError: No module named 'stackoverflow_clone.local_settings'
Is this error occuring because local_settings.py
is being treated as if it doesn't exist at all?
How can the error be resolved so that configuration such as SECRET_KEY
can be imported?
This directory structure reflects what's on my local machine.
(stackoverflow_clone-virtualenv) 23:19 ~ $ pwd
/home/ittybitty
(stackoverflow_clone-virtualenv) 23:19 ~ $ ls
README.txt django_stackoverflow
(stackoverflow_clone-virtualenv) 23:19 ~ $ cd django_stackoverflow
(stackoverflow_clone-virtualenv) 23:19 ~/django_stackoverflow (main)$ ls -l
-rw-rw-r-- 1 ittybitty registered_users 22 Feb 12 19:09 README.md
drwxrwxr-x 7 ittybitty registered_users 4096 Feb 12 19:09 authors
-rw-rw-r-- 1 ittybitty registered_users 675 Feb 12 19:09 manage.py
drwxrwxr-x 4 ittybitty registered_users 4096 Feb 12 19:09 node_modules
-rw-rw-r-- 1 ittybitty registered_users 369 Feb 12 19:09 package-lock.json
-rw-rw-r-- 1 ittybitty registered_users 569 Feb 12 19:09 package.json
-rw-rw-r-- 1 ittybitty registered_users 8581 Feb 12 19:09 paginated_db_set.json
drwxrwxr-x 7 ittybitty registered_users 4096 Feb 12 19:09 posts
-rw-rw-r-- 1 ittybitty registered_users 107 Feb 12 19:09 requirements.txt
drwxrwxr-x 3 ittybitty registered_users 4096 Feb 12 23:12 stackoverflow_clone
drwxrwxr-x 2 ittybitty registered_users 4096 Feb 12 19:09 templates
drwxrwxr-x 4 ittybitty registered_users 4096 Feb 12 19:09 web_assets
(stackoverflow_clone-virtualenv) 23:19 ~/django_stackoverflow (main)$ ls -l stackoverflow_clone
total 20
-rw-rw-r-- 1 ittybitty registered_users 0 Feb 12 19:09 __init__.py
drwxrwxr-x 2 ittybitty registered_users 4096 Feb 12 23:13 __pycache__
-rw-rw-r-- 1 ittybitty registered_users 415 Feb 12 19:09 asgi.py
-rw-rw-r-- 1 ittybitty registered_users 4034 Feb 12 23:12 settings.py
-rw-rw-r-- 1 ittybitty registered_users 3247 Feb 12 19:09 urls.py
-rw-rw-r-- 1 ittybitty registered_users 415 Feb 12 19:09 wsgi.py
/var/www/ittybitty_pythonanywhere_com_wsgi.py
# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
# assuming your django settings file is at '/home/ittybitty/mysite/mysite/settings.py'
# and your manage.py is is at '/home/ittybitty/mysite/manage.py'
path = '/home/ittybitty/django_stackoverflow'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'stackoverflow_clone.settings'
# then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()