I am having very frustrating issues with PythonAnywhere. I've managed to get my site up and running by doing some hacky work arounds whenever I need to run manage.py but now that I need to set an automated task, this is no longer an option.
The issue lies in the fact that in PythonAnywhere databases have to be named in the convention "user$database". Because of the dollar sign, whenever I run something like python manage.py inspectdb
I get the error mentioned in the title as anything attached to the dollar signed is assumed to be an environment variable by the shell.
Currently, I am storing my production environment variables in a .env file and setting them in to the settings.py file. This works internally with Django but does not work when running manage.py commands in the shell. I've attempted to fix the problem by adding the following code in my manage.py file:
# update DATABASE_NAME to use \$ instead of $ else bash commands wont work
os.putenv(
"DATABASE_NAME",
str(os.getenv("DATABASE_NAME")).replace('$', '\\$')
)
however, this does not resolve the issue.
I've also attempted to resolve the by creating a file called production_settings.py containing my DATABASES settings and wrapping the database name in single quotes alongside my settings.py file then inserting the following code in my settings.py file to set my DATABASES settings:
try:
from production_settings import DATABASES
except ImportError:
pass
Again, this did not work. I've tried finding support with PythonAnywhere but there doesn't seem to be any so I've come here in hopes someone here knows how to resolve the issue. I am days behind now... What should I do???
That sounds like you need to put single quotes around the values in your env file.