skip to Main Content

I’ve tried so much and feels i’m stuck and not getting anywhere Apache is giving an error which is

ModuleNotFoundError: No module named ‘wearpretty.settings’

I’m using
python 3.6,
Django2.1,
apache2,
libapache2-mod-wsgi-py3

Below are the files which are being used in this.

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ["DJANGO_SETTINGS_MODULE"] = "wearpretty.settings"
application = get_wsgi_application()

virtualhost.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName lhwearpretty.com
    ServerAlias www.lhwearpretty.com
    DocumentRoot /var/www/myprojects/wearpretty/wearpretty/wearpretty

    <Directory /var/www/myprojects/wearpretty/wearpretty/wearpretty>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/venv python-path=/var/www/myprojects/wearpretty
    WSGIProcessGroup lhwearpretty.com
    WSGIScriptAlias / /var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py

    Alias /static/ /var/www/myprojects/wearpretty/wearpretty/static/ 

    <Directory /var/www/myprojects/wearpretty/wearpretty/static> 
        Require all granted 
    </Directory>
</VirtualHost>

2

Answers


  1. Chosen as BEST ANSWER

    As i started this myself i figured out there's some issue with naming of my directories. Anyone who's starting first time he should be aware you can't use your Site dir name as your Project name. so i changed it.

    Old Structure

    Site Dir = /var/www/myprojects/wearpretty
    Project Dir = /var/www/myprojects/wearpretty/wearpretty
    venv = /var/www/myprojects/wearpretty/venv
    

    New Structure

    Site Dir = /var/www/myprojects/wearpretty
    Project Dir = /var/www/myprojects/wearpretty/mysite
    venv = /var/www/myprojects/wearpretty/venv
    

    Virtualhost.conf

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName lhwearpretty.com
        ServerAlias www.lhwearpretty.com
        DocumentRoot /var/www/myprojects/wearpretty/mysite
    
    
        WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/wearprettyenv python-path=/var/www/myprojects/wearpretty/mysite
        WSGIProcessGroup lhwearpretty.com
        WSGIScriptAlias / /var/www/myprojects/wearpretty/mysite/mysite/wsgi.py
    
    
        <Directory /var/www/myprojects/wearpretty/mysite>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    
        Alias /static/ /var/www/myprojects/wearpretty/mysite/static/ 
    
        <Directory /var/www/myprojects/wearpretty/mysite/static> 
            Require all granted 
        </Directory>
    </VirtualHost>
    

    Hopefully This'll help others as well.


  2. Your DocumentRoot should be one folder up (minus 1 /wearpretty) and python-path var in WSGIDaemonProcess should be one down (plus 1 /wearpretty) : they must point to you Django Project root.

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName lhwearpretty.com
        ServerAlias www.lhwearpretty.com
        DocumentRoot /var/www/myprojects/wearpretty/wearpretty
    
        <Directory /var/www/myprojects/wearpretty/wearpretty/wearpretty>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    
        WSGIDaemonProcess lhwearpretty.com python-home=/var/www/myprojects/wearpretty/venv python-path=/var/www/myprojects/wearpretty/wearpretty
        WSGIProcessGroup lhwearpretty.com
        WSGIScriptAlias / /var/www/myprojects/wearpretty/wearpretty/wearpretty/wsgi.py
    
        Alias /static /var/www/myprojects/wearpretty/wearpretty/static/ 
    
        <Directory /var/www/myprojects/wearpretty/wearpretty/static> 
            Require all granted 
        </Directory>
    </VirtualHost>
    

    Also, I would recommend to add this Directory node :

    <Directory /var/www/myprojects/wearpretty/wearpretty>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search