I am following the instructions on Heroku for using Memcahier with Python.
When trying to use the 'mc' variable, which is set in settings.py, in another file I get the following error:
Exception Value: name 'mc' is not defined
I have tried importing settings.py into the file I wish to use the 'mc' variable but I get another error:
'Settings' object has no attribute 'mc'
How can I access this mc variable outside of the settings file?
This is probably an importing issue.
You need to access mc
via settings.mc
, because, provided you imported it using import settings
at the beginning of the file, it is not included in your current namespace, but in a seperate one called "settings".
If you whish to import it directly into your current namespace, use
from settings import *
instead.
This only works, when your own file is in the same directory as settings.py, or if settings.py is in a directory known to Python. (See PYTHONPATH)
If settings.py is in another Directory, you could for example Import it using the whole path
It never hurts to skim over the Python docs, by the way: see this
Also, make sure to use the correct case for your settings module. If the settings file is imported as "settings" with a lowercase letter, then you have to access it like that all over the place, because Python is case sensitive