Forums

"No module named" problem

I setup a mezzanine project successfully.

In the settings.py (Python2.7) consol :

>>> mezzanine.pages.models import Page
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mezzanine/pages/models.py", line 2, in <module>
from django.db import models
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % 
ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Why this error?

DJANGO_SETTINGS_MODULE variable has been set up :

# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:

import os
import sys

## assuming your django settings file is at '/home/myname/mysite/settings.py'    
path = '/home/sligozat/'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'nettementvotre.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Hi sligozat,

The standard PythonAnywhere Python consoles don't run any code before launching. If you want to import your models you will need to open a bash console, navigate to your Mezzanine app directory and launch a Python process via manage.py. This loads a Python process with all correct environment already set up. So in a bash console type:

/home/sligozat/nettementvotre
python manage.py shell

Then in the resulting IPython shell you can do:

mezzanine.pages.models import Page

The second code is in your /var/www/wsgi.py file? That will work but it is only run when the mezzanine application is accessed as a web page.

Hello, I am having the same issue here. I cannot start the mezzanine based web application I have a "ImportError at /

No module named models"

here is my wsgi file

+++++++++++ DJANGO +++++++++++

import os import sys path = '/home/myaccount/' sys.path.append(path) path = '/home/myaccount/my_project_dir/' sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'my_project_dir.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()

I fixed that problem. But now I am running into my css and js, basically none of my static files being served. I used the static mapping thoug... but I am not sure now what's going on

Ok looks like I grasped the pythonanywhere way of doing things... I just followed the the FAQs ... for the admin interface, I had to add /media at the end, that make it work perfectly

2017-04-16 01:48:34,318 :Error running WSGI application 2017-04-16 01:48:34,318 :ImportError: No module named my_wsgi_file 2017-04-16 01:48:34,318 : File "/var/www/ipproject_pythonanywhere_com_wsgi.py", line 71, in <module> 2017-04-16 01:48:34,318 : from my_wsgi_file import application

help me out of this error please

Take a look at this help page.