Hey everyone. I'm new to Python and Django, and I've been trying to get Django up and running for over 10 hours now. I've scoured the web, but with very little good documentation available, I thought I'd ask others for help. I'm trying to write a program which will connect to my database, but I can't even get started because Django is throwing fits. Here is the code I'm trying to run:
import os
import sys
from django.db import connection
print(sys.path)
It produces this error:
from django.db import connection
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 134, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'NewMKEProject.settings.py' (Is it on sys.path?): cannot import name connection
This is what the relevant portion of my settings.py file looks like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'C:\\Users\\USER NAME\\Documents\\Aptana Studio 3 Workspace\\NewMKEProject\\mysql.db',
'USER': 'MKExpenses',
'PASSWORD': 'MY PASSWORD',
'HOST': 'MY HOSTNAME',
'PORT': '',
}
}
And this is my manage.py file:
#!/usr/bin/env python
import os, sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "NewMKEProject.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
So, I've taken everyone's suggestions and tried adding this just above the django import:os.environ.setdefault("DJANGO_SETTINGS_MODULE", "NewMKEProject.settings")
but it doesn't work.
I've added the project folder and parent folder to PYTHONPATH. I've added the django folder as an external library. None of this has worked. Can anybody help me out?
I'm using Python 2.7.
Thanks for your help.