Django 1.7 import error: no module named mysite - django

I am a newbie to Django, trying to test run with Apache and mod_wsgi with Windows.
This is my httpd conf:
WSGIScriptAlias /hm "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite/wsgi.py"
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite">
Options Indexes FollowSymLinks +ExecCGI
Order deny,allow
Allow from all
Allow from all
AddHandler wsgi-script .py
</Directory>
I have this project structure:
mysite
-manage.py
-mysite
-settings.py
-wsgi.py
In my wsgi, I have:
import os, sys
base = os.path.dirname(os.path.dirname(__file__))
sys.path.append(base +"\\mysite" )
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Why do I get import error: no module named mysite ?

Related

500 Internal Server Error in production - Django

I'm very new in django and I am in deploying phase of a project. But after all setup, it shows 500 internal server error and the apache2 error log says ImportError: No module named 'backend'
I tried to edit wsgi.py as I thik this is the one giving this error
this is content of my wsgi.py file
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
application = get_wsgi_application()
settings/dev.py
DEBUG = True
ALLOWED_HOSTS = ['my_ip_address']
WSGI_APPLICATION = 'backend.wsgi.application'
manage.py
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Directory Structure:
atms
--backend
--wsgi.py
--urls.py
--settings
--dev.py
--manage.py
pip freeze:
cairocffi==0.9.0
CairoSVG==2.2.1
cffi==1.11.5
cssselect2==0.2.1
defusedxml==0.5.0
Django==2.1.5
django-countries==5.3.2
django-weasyprint==0.5.4
djangorestframework==3.9.1
gunicorn==19.9.0
html5lib==1.0.1
Pillow==5.4.1
pycparser==2.19
Pyphen==0.9.5
pytz==2018.9
six==1.12.0
tinycss2==0.6.1
WeasyPrint==44
webencodings==0.5.1
whitenoise==4.0
atms.conf in /etc/apache2/sites-avalible
Alias /static /home/atms/atms/public/static
<Directory /home/atms/atms/public/static>
Require all granted
</Directory>
Alias /media /home/atms/atms/media
<Directory /home/atms/atms/media>
Require all granted
</Directory>
<Directory /home/atms/atms/backend>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/atms/atms/backend/wsgi.py
WSGIDaemonProcess django_app python-path=/home/atms/atms/backend python-home=/home/atms/venv
WSGIProcessGroup django_app
the error log says
ImportError: No module named 'backend'
You've put backend directly on your python-path, which means that is not itself an importable name. You should put the parent directory there instead:
WSGIDaemonProcess django_app python-path=/home/atms/atms python-home=/home/atms/venv

ImportError: No module named site deploying Django with mod-wsgi and httpd

I'm trying to deploy a django project on CentOS 7, but I keep getting ImportError: No module named site on my httpd error log.
This is my config file for httpd located at /etc/httpd/conf.d:
<VirtualHost *:8008>
WSGIProcessGroup programa_registos
WSGIDaemonProcess programa_registos python-home=/var/www/html/programa_registos/.env python-path=/var/www/html/programa_registos
Alias /static /var/www/html/programa_registos/static
<Directory /var/www/html/programa_registos/static>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/html/programa_registos/programa_registos/wsgi.py
<Directory /var/www/html/programa_registos/programa_registos>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
My project is located at /var/www/html/programa_registos and my virtualenv at /var/www/html/programa_registos/.env.
Here is my wsgi.py file, located at /var/www/html/programa_registos/programa_registos:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "programa_registos.settings")
application = get_wsgi_application()

Unable to run my Django Site (Version 1.6) on Apache Server

I am running a site that was previously running on django 1.4, but now I shifted it on django 1.6.
I am able to run my site on both version using python manage.py shell.
I am running it nicely on Apache when i keep django 1.4 virtual environment python path in Apache site-enabled, but it does not work when i keep django 1.6 virtual environment python path there.
For django 1.6 it throws error:
ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
What can be problem? Any changes required in wsgi.py file for django 1.6? Please help.
my virtualhost file is :
<VirtualHost *:80>
ServerAdmin vidya.sagar0911#gmail.com
DocumentRoot /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/
ServerName www.vidblog.com
<Directory /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo>
#Order deny,allow
#Allow from all
Options FollowSymLinks
AllowOverride None
</Directory>
Alias /media /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/vidyamedia/
Alias /static /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/static/
WSGIDaemonProcess www.demo.com user=www-data group=www-data processes=8 threads=75\
python-path=/home/vidya/workspace/djnago1.6/lib/python2.7/site-packages
WSGIProcessGroup www.vidblog.com
WSGIScriptAlias / /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/demo/wsgi.py
</VirtualHost>
This is the issue when you are migrating your old projects from django-1.x(<1.6) to django-1.6 you need to define DJANGO_SETTINGS_MODULE before you call get_wsgi_application
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Django webfaction deployment: How to change the default directory of your project

im deploying my django project, named "Hesperides" under a webfaction server. The default project's folder in webfaction it's "myproject" so Im having this error:
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named myproject.settings
The question is: How can i do to import the settings from Hesperides.settings instead from myproject.settings? Thanks for your time.
My httpd.conf:
WSGIDaemonProcess jinn processes=2 threads=12 python-path=/home/zeioth/webapps/jinn:/home/zeioth/webapps/jinn/myproject:/home/zeioth/webapps/jinn/lib/python2.7:
WSGIScriptAlias / /home/zeioth/webapps/jinn/myproject/Hesperides/wsgi.py
My wsgi.py
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'Hesperides.settings'
application = WSGIHandler()
My folder tree:
jinn
--apache2
-bin
--conf
-httpd.conf
-mime.types
-lib
-logs
-modules
-bin
-lib
--myproject
-manage.py
--Hesperides
-wsgi.py
-urls.py
-__init__.py
-settings.py
-apps
PROBLEM SOLVED: These are the steps to change your project directory under webfaction:
1-in httpd.conf in webapps/yourappname/apache2 set:
WSGIScriptAlias / /home/zeioth/webapps/jinn/myproject/yourNewName/wsgi.py
2-in your app's manage.py set:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourNewName.settings")
3-in your app's wsgi.py set:
os.environ['DJANGO_SETTINGS_MODULE'] = 'yourNewName.settings'
4-In your app's settings.py set:
WSGI_APPLICATION ='yourNewName.wsgi.application'
Now, runserver should work, or tell you if you need to install some module.
Note that when you have use WSGIDaemonProcess you need to have a corresponding WSGIProcessGroup directive else your WSGI application will not be delegated to run in that daemon process group. WebFaction was generating a broken configuration file for a while if I remember. That or you copied this from one of the blog posts out there which have broken examples. Read:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Embedded_Or_Daemon_Mode

django 1.4 with apache virtualhost - path problems

I'm trying to upgrade my application from django 1.2 to 1.4, which I have tested successfully with the inbuilt webserver.
However, I am having problems with deploying it as a VirtualHost with Apache (on Ubuntu).
my sites-available/default contains:
<VirtualHost *:80>
ServerName myapplication
WSGIScriptAlias / /usr/share/myapplication/wsgi.py
WSGIDaemonProcess myapplication python-path=/usr/share/myapplication:/usr/lib/python2.6/dist-packages
<Directory /usr/share/myapplication>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
the file /usr/share/myapplication/wsgi.py contains the standard:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapplication.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Apache will start ok, but when I go to http://myapplication I get '500: Internal Server Error' and the apache logs show:
ImportError: Could not import settings 'WCReporter.settings' (Is it on sys.path?): No module named WCReporter.settings
Am I using WSGIDaemonProcess correctly? The django docs aren't clear.
Thanks
Solved this with the following, from http://rc98.net/django_wsgi.
sites-available/default:
<VirtualHost *:80>
ServerName myapplication
WSGIDaemonProcess myapplication
WSGIProcessGroup myapplication
WSGIScriptAlias / /usr/share/myapplication/wsgi.py
<Directory /usr/share/myapplication>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
and wsgi.py:
import os,sys
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
sys.path.append(path)
path = '/usr/share/myapplication'
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapplication.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Could you print your path at runtime:
#init.py
import sys
print sys.path
have you got an init file in the project base dir?
does it work if you import settings instead of myapp.settings?