1

I have a Django project, version 1.8.7

I am trying to run manage.py.

The manage.py scrip produces an error:

ImportError: No module named project_name.settings

My directory structure is like this:

project_name:
     - __init__.py
     - other_stuff
     - ...
     - settings.py
     - manage.py

In manage.py I have a line of code like this:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")

If I change project_name.settings to settings. I don't get this error anymore ( I get another error down the line, also an import error, but that is besides the point )

On other machines the code works with project_name.settings.

I imagine this is a pathing issue. How, or better put, where can I fix this path issue? Specifically, how can I tell Django that project_name.settings is actually current_directory.settings?

Thanks!

ANSWER:

So, the fix I found was to make a symlink in the dist-packages of python. I have a symlink, let's call it s, that points to the directory containing my project. The symlink s points to parent_dir.

- parent_dir
     - dir_1
     - ...
     - project_name
           - __init__.py
           ...
     - ...

I also added a pth file, s.pth that contains just the name of the symlink, s.

Now, it works.

RandomGuyqwert
  • 425
  • 6
  • 18
  • Are you using virtualenv? – Alex Morozov Jan 18 '16 at 13:01
  • The way to explicitly tell Django to use the `settings.py` file in the root project folder is what you suggest works in your question, `os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")` – gtlambert Jan 18 '16 at 13:05
  • Alternatively, you can declare the location of your `settings.py` file using the `--settings` option when you run the server locally, eg `python manage.py runserver --settings=settings` – gtlambert Jan 18 '16 at 13:09

0 Answers0