Following the directory structure in the answer here:
Best practice for Django project working directory structure
Reviewed the code on GitHub here to troubleshoot:
I moved the manage.py
into a scripts
directory. I modified the manage.py
and wsgi.py
to have these lines:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
Instead of the default:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj_dir.settings")
Which I think is basically equivalent.
Anyway, this is the error I get when I run python manage.py runserver
:
File "C:\Users\ISH~1\DJANGO~1\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named '{{ project_name }}'
I have tried using relative imports, but really not getting anywhere to resolve the issue. Being a newb, I am sure the answer is pretty obvious, but I have spent a few hours reading about the problem and not really getting anywhere.
One suggested adding from . import *
but this just resulted in:
Traceback (most recent call last):
File "manage.py", line 4, in <module>
from . import *
SystemError: Parent module '' not loaded, cannot perform relative import
virtualenv
is active and I running manage.py
from the correct directory. Works fine when it is not in /scripts/
.
EDIT:
I didn't mentioned this, but regardless of whether in manage.py
it is:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj_dir.settings")
Or:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name )).settings")
The result is always ImportError: No Module named 'xyz'
. Fill in xyz
with anything before settings
.
Also, the above indicates, my project isn't 100% implemented like what is discussed in the first link. My settings.py
is still in the default location. It looks like this basically:
~/projects/django-project
/proj_dir
settings.py
urls.py
wsgi.py
/scripts
manage.py
Also, I tried this because I thought well it might be looking for proj_dir
in scripts
and I actually want it to go up a level to look for proj_dir
.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", ".proj_dir.settings")
This just brings up the following error.
TypeError: the 'package' argument is required to perform a relative import for '.proj_dir.settings'
That is when I started messing around with import
and from . import
because documentation was saying the error was related to that. Still couldn't fix the issue.