ImportError: No module named django.core.wsgi - django

I am getting this error while deploying django project on uwsgi and nginx server
ImportError: No module named django.core.wsgi

Check Django Version
Make sure settings.py is loaded in to env properly.

Related

Adding whitenoise to django gives an "ImproperlyConfigured: WSGI application" error

My application works if I were not to add
"whitenoise.middleware.WhiteNoiseMiddleware"
into the MIDDLEWARE in settings.py
but if I were to add it back, then it would not work and would give this error
django.core.exceptions.ImproperlyConfigured: WSGI application 'story_4.wsgi.application' could not be loaded; Error importing module.
This is what is inside my wsgi.py file
#wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'story_4.settings')
application = get_wsgi_application()
Any answer is appreciated.
Problem solved, Please remember to update your Whitenoise to the latest version with pip install --upgrade whitenoise
Mine was still at 3.3.0 and apparently django didn't like it.

How to set `Procfile` for a Mezzanine app deployed on Heroku

I already have a Mezzanine app deployed on Heroku. The system ran OK before, but today the web page showed an error message Internal Server Error. Checked with heroku logs and found that the command web python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 1 is deprecated and Heroku suggests using <projName>.wsgi:application.
But Mezzanine currently has different project layout from Django (Mezzanine's settings.py is in the project root directory), so I tried the following in Procfile:
web: gunicorn wsgi --log-file -
However, such a setting results in error message:
ImportError: No module named 'app'
...
ImportError: Could not import settings 'app.settings' (Is it on sys.path? Is there an import error in the settings file?) No module named 'app'.
Then I tried:
web: gunicorn <projName>.wsgi --log-file -
The error message (of course ;-):
ImportError: No module named '<projName>'
So, how do I set Procfile so that gunicorn is able to find the project's settings.py and wsgi.py?

how should i add python path in wsgi.py when using virtualenv

I am trying to deploy a django website using apache2.4, mod_wsgi on ubuntu 14.04.
The problem is that my wsgi.py file is unable to import django. this obviously means that i have not set python path for the virtualenv. But i am a little confused as to how to add python path of virtuaenv's site-packages.
my wsgi.py is:
import os
import sys
sys.path.append('/home/sp/webapps')
sys.path.append('/home/sp/webapps/ilog_dev')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ilog_dev.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
so the question is how should i add the virtualenv's site-package to python path
Have you tried path/to/virtualenv/activate before doing anything? Or maybe you didn't use virtualenv's python instead of global python.

ImportError: cannot import name get_path_info

My question is why foreman start not serving css file in dev environment ...? but my app running perfectly fine in heroku production server. Correct me if i am wrong, i thought dj-static is the only option for serving static in foreman env, so in order to work dj-static in wsgi.. follows...
wsgi.py
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
if i am changing above code to
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "readtamil.settings")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
then foreman start gives me this error
ImportError: cannot import name get_path_info
Try setting dj-static==0.0.6 in your requirements.txt file for Virtualenv. There might be a versioning issue on PyPI or a Django1.7 issue or the Heroku tutorial shows to use 0.0.5.
I've reported this issue to Heroku and their tutorial is now updated to reflect newer versions in the requirements.txt.

Django WSGI and Gunicorn

This might be really stupid question; I'm trying to deploy Django application using Gunicorn. However, I just created wsgi.py which looks like below (wsgi.py is in my root project folder):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
and now I ran:
python manage.py run_gunicorn
Will Gunicorn automatically picks up this wsgi.py? How does this work? (not sure what wsgi is doing). Or do i need to specify something?
If you have gunicorn listed in INSTALLED_APPS of Django settings module, the command is:
python manage.py run_gunicorn
Not the command you give.
I have Gunicorn to host my django site and this is the config details hope this is helpfull