I have a Python file thats part of the Django framework called facade.py
from django.conf import settings
from .gateway import Gateway
class Facade(object):
def __init__(self):
self.gateway = Gateway(
settings.password,
settings.username,
)
I want to test this code in my terminal window. This is what I have tried:
within virutal-env
python
>>> from my.apps.app.facade import Facade
>>> object = Facade()
but this give me the error ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Why?
You should not do this in a plain Python shell. Start the shell with Django configured by doing ./manage.py shell instead of just python.
Try adding this:
from django.conf import settings
if not settings.configured:
settings.configure()
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With