How to troubleshoot - ImportError: Could not import settings 'mysite.settings' when deploying django?

前端 未结 2 2134
情话喂你
情话喂你 2021-01-14 17:44

I\'ve had my django app deployed and working perfectly with apache and mod_python, according to the apache deployment instructions. But since I changed the project structure

2条回答
  •  醉话见心
    2021-01-14 17:57

    for my Django 1.5 and mod_wsgi, I resolved it like this:

    httpd.conf:

    WSGIScriptAlias /mysite "/var/www/html/mysite/mysite/wsgi.py"
    WSGIPythonPath  "/var/www/html/mysite/mysite"
    
        Order deny,allow
        Allow from all
    
    

    wsgi.py:
    the sys.path.append(path) to let mysite.settings known

    import os
    import sys                                              #new
    path = '/var/www/html/mysite'                           #new
    if path not in sys.path:                                #new
        sys.path.append(path)                               #new
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

    another thing, to avoid error like below

    Premature end of script headers: wsgi.py
    

    you need remove cgi configure from httpd.conf

    AddHandler cgi-script .py  
    

提交回复
热议问题