ImportError: No module named mysite.settings (Django)

前端 未结 5 734
清酒与你
清酒与你 2020-12-31 06:37

I have installed Django and mod_wsgi-express on an ubuntu 15.10. Basically (notice I did not do this as root):

pip install Django
pip instal         


        
相关标签:
5条回答
  • 2020-12-31 07:15

    The problem was in the include path:

    import sys
    #Wrong!
    #sys.path.append("/home/user/mysite/mysite")
    
    #Correct
    sys.path.append("/home/user/mysite")
    
    0 讨论(0)
  • 2020-12-31 07:21

    I had this error too, when I was trying to move a windows project to Debian.

    import sys
    sys.path.append("your project path")
    
    0 讨论(0)
  • 2020-12-31 07:25

    Please try:

    
        import os
        import sys
        BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        sys.path.append(BASE_DIR)
        os.environ['DJANGO_SETTINGS_MODULE'] = 'YOURAPP.settings'
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "YOURAPP.settings")
    

    This is working for scripts in main project directory, as well ..

    0 讨论(0)
  • 2020-12-31 07:29

    add this to your wsgi.py file

    path = '/home/path/to/project'
    if path not in sys.path:
        sys.path.append(path)
    

    before setting

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    
    0 讨论(0)
  • 2020-12-31 07:36

    Also, if you are using Visual Studio, check that your app properties for Django match the settings module that you are expecting. By default, it is set to $(MSBuildProjectName).settings, which was a problem for me since my project name and app name were not the same.

    You can find this setting by right clicking on your app in the Solution Explorer and clicking on "Properties" and then the Django tab on the left.

    0 讨论(0)
提交回复
热议问题