How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?

前端 未结 15 1931
渐次进展
渐次进展 2020-12-04 11:15

I can\'t get wsgi to import my settings file for my project \'mofin\'.

The list of errors from the apache error log are as follows

mod_wsgi (pid=4001         


        
相关标签:
15条回答
  • 2020-12-04 11:36

    I had the same problem but another solution :

    My project folder was named exactly as one of my application.

    I had :

    /home/myApp
    /home/myApp/settings.py
    /home/myApp/manage.py
    /home/myApp/rights.py
    /home/myApp/static/
    /home/myApp/static/
    /home/myApp/myApp/model.py
    /home/myApp/myApp/admin.py
    /home/myApp/myApp/views.py

    This kind of tree doesn't seems to be possible easily. I changed the name of my project root folder and the problem was solved!

    0 讨论(0)
  • 2020-12-04 11:37

    In my case, I had a circular import that was causing this error. From settings.py I was importing one function in another module, and from that module I was importing a settings variable. To fix it, instead of directly importing from settings, I did this:

    from django.conf import settings
    
    0 讨论(0)
  • 2020-12-04 11:41

    (I wrote up this same answer for Django deployment problem in Apache/mod_wsgi. ImportError: Could not import settings 'site.settings' in case someone only finds this question.)

    This doesn't appear to be the problem in your case, but I ran smack into the same ImportError when I used the WSGIPythonPath directive (instead of the .wsgi file) to set up sys.path. That worked fine until I switched to running WSGI in daemon mode. Once you do that, you have to use the python-path argument to the WSGIDaemonProcess directive instead.

    0 讨论(0)
  • 2020-12-04 11:44

    Another cause of this problem is that you can't name your application the same as another python module. For example I called mine site, little realising that site is already a python module.

    You can check this by starting python, and running import site, help(site), and it will show you it isn't using your module. This of course gives you errors when django tries to import site.settings which doesn't exist.

    0 讨论(0)
  • 2020-12-04 11:44

    Let me add and my experience for that issue. After head banging for few hours and try all from the above answers I found that few lines in settings.py file cause the problem:

    from south.modelsinspector import add_introspection_rules
    add_introspection_rules([], ["^dynamicsites.fields.FolderNameField"])
    add_introspection_rules([], ["^dynamicsites.fields.SubdomainListField"])
    

    After that I made copy of the settings.py, named scripts_settings.py whithout that lines, and used that file and everything is ok now.

    0 讨论(0)
  • 2020-12-04 11:44

    I had a similar problem, solved it with the following snippet in my python:

    ALLDIRS = ['/var/www/MarkerDB/']
    
    import sys 
    import site 
    
    # Remember original sys.path.
    prev_sys_path = list(sys.path) 
    
    # Add each new site-packages directory.
    for directory in ALLDIRS:
      site.addsitedir(directory)
    
    # Reorder sys.path so new directories at the front.
    new_sys_path = [] 
    for item in list(sys.path): 
        if item not in prev_sys_path: 
            new_sys_path.append(item) 
            sys.path.remove(item) 
    sys.path[:0] = new_sys_pat
    

    Source: http://code.google.com/p/modwsgi/wiki/VirtualEnvironments#Application_Environments

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