简体   繁体   中英

ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings

editing to try and troubleshoot with first answer.

Now I am getting 403 forbidden. This is what I have:

<VirtualHost ip:80>
    ServerAdmin admin
    ServerName name
WSGIScriptAlias / /home/django/mysite/mysite/wsgi.py

<Directory /home/django/mysite/mysite>
<Files wsgi.py>
     Require all granted
</Files>
</Directory>
</VirtualHost>

I have a user created "django" /home/django and all subdirectories have permissions of "django". This is how it should be, correct?

I am running django 1.6.2

/home/django contains mysite, and '/home/django/mysite' contains manage.py. /home/django/mysite/mysite/ contains, init, urls, and wsgi.py.

wsgi.py contains:

import os
import sys
sys.path.insert(0,'/home/django/mysite')

os.environ["DJANGO_SETTINGS_MODULE"] =  "mysite.settings"

# NOTICE: the following may only work well in django version 1.5 1.6
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

What am I doing wrong? Why am I getting forbidden? :( Does wsgi.py need to be user/group apache?

If it matters, Server version: Apache/2.2.15

Could it possibly have anything to do with mod_userdir.c?

I usually write it in wsgi.py using mod_wsgi

configuration in *.conf (Apache version >= 2.4):

<VirtualHost *:80>
        ServerName example.com
        ServerAdmin example@example.com

        Alias /media/ /home/tu/blog/media/
        Alias /static/ /home/tu/blog/collected_static/

        <Directory /home/tu/blog/media>
                Require all granted
        </Directory>

        <Directory /home/tu/blog/collected_static>
                Require all granted
        </Directory>

        WSGIScriptAlias / /home/tu/blog/blog/wsgi.py

        <Directory /home/tu/blog/blog>
        <Files wsgi.py>
                Require all granted
        </Files>
        </Directory>
</VirtualHost>

if you use Apache 2.2 use

Order allow,deny
Allow from all

instead of

Require all granted

wsgi.py (depends on your django version)

import os
import sys
sys.path.insert(0,'/path/to/project/')

os.environ["DJANGO_SETTINGS_MODULE"] =  "project.settings"

# NOTICE: the following may only work well in django version 1.5 1.6
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

That is, regard your django project as a python package, sys.path used to tell python where the project is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM