0
votes

Thanks in Advance for My Query.

I have created a django project which has manage.py file inside src folder it works fine when running terminal from SRC folder.

FOr Heroku deployement manage.py should be placed in root directory so i updated manage.py file with "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.tweetme.settings")"

Changed "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tweetme.settings")" to "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.tweetme.settings")" import issue is faced on running locally. Need solution how to import setting.py inside two folder deep.

#!/usr/bin/env python

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.tweetme.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

I am facing following Error: attached Error_Message.png

Hiras-Mac-mini-2:tweethere apple$ python manage.py runserver Traceback (most recent call last): File "manage.py", line 23, in execute_from_command_line(sys.argv) File "/Library/Python/2.7/site-packages/django/core/management/init.py", line 363, in execute_from_command_line utility.execute() File "/Library/Python/2.7/site-packages/django/core/management/init.py", line 307, in execute settings.INSTALLED_APPS File "/Library/Python/2.7/site-packages/django/conf/init.py", line 56, in getattr self._setup(name) File "/Library/Python/2.7/site-packages/django/conf/init.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/Library/Python/2.7/site-packages/django/conf/init.py", line 110, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module import(name) ImportError: No module named src.tweetme.settings

***This Is my Package Structure:***attached Project_Structure.png

-Project
    -bin
    -include
    -lib
    -src
       -subProject1
       -subProject2
       -subProject3
       -mainProject
             -Settings
                 -__init__.py
                 -base.py
                 -local.py
                 -production.py
       -manage.py
       -db.sqlite3
    -static-serve
       -.env
       -.python
       -manage.py
       -ProcFile
      -requirements.txt

Project_Structure.pngError_Message.png

1
Your question is confusing because you use a mixture of real directory names like tweethere and made-up names like mainProject. It would be much clearer if you used the real name everywhere.Alasdair

1 Answers

0
votes

If manage.py is not in the src directory, then you need to add src to the Python path.

import sys
sys.path.append('src')

You should then keep DJANGO_SETTINGS_MODULE as it was, without src.

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