1

I'am having this issue with django + wsgi, and I can't understand why. When I go to my local website running with apache2 + wsgi, I have this error :

ImportError at /
No module named models

But when i run with development server, everything is ok : python manage.py runserver 0:8080.

My wsgi.py :

import os, sys

sys.path.append('/var/www/reader')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "reader.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

My models.py

from django.db import models
from django.contrib.auth.models import User

class Feed(models.Model):
    display_name = models.CharField(max_length=255)
    link_feed = models.CharField(max_length=255)
    user = models.ForeignKey(User)

My views.py where the error is throwed :

from django.shortcuts import render
from reader.models import Feed

def index(request):
    feeds_list = Feed.objects.all()
    context = {'feeds_list': feeds_list}
    return render(request, 'home/index.html', context)

And in my settings :

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'reader', <-- this is my app
)

I run under Python 2.7.4 and django 1.5.1.

Could someone explain to me why please ?

Update 1 :

jeremy@dev:/var/www/reader$ tree .
.
├── manage.py
└── reader
    ├── __init__.py
    ├── models.py
    ├── reader.settings
    ├── settings.py
    ├── static
    │   ├── images
    │   ├── scripts
    │   │   └── script.js
    │   └── styles
    │       └── style.css
    ├── templates
    │   ├── base.html
    │   ├── home
    │   │   └── index.html
    │   └── subscription
    │       └── add.html
    ├── urls.py
    ├── views.py
    └── wsgi.py

8 directories, 13 files
raul
  • 327
  • 2
  • 12
United
  • 11
  • 3

1 Answers1

0

make sure that in your project's app reader that there is an __init__.py file

project/
-- reader/
---- __init__.py 
---- models.py
---- views.py

Debug help

Do you have tree installed?

if not brew install tree or apt-get install tree (change for your flavor of dev env.)

run

cd ~/path/to/djangoproject
tree .

and then paste the output up top so we can get a better idea of whats going on.

francis at Kraken.local  ~/Sites/yaconiello/blog on francis*
$ tree .
.
├── __init__.py
├── __init__.pyc
├── admin
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── article.py
│   ├── article.pyc
│   ├── category.py
│   └── category.pyc
├── feeds
│   ├── __init__.py
│   ├── category.py
│   └── latest.py
├── migrations
│   ├── 0001_initial.py
│   ├── 0001_initial.pyc
│   ├── 0002_auto__add_field_article_excerpt.py
│   ├── 0002_auto__add_field_article_excerpt.pyc
│   ├── __init__.py
│   └── __init__.pyc
├── models
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── article.py
│   ├── article.pyc
│   ├── category.py
│   ├── category.pyc
│   ├── request.py
│   └── vote.py
├── signals.py
├── signals.pyc
├── templates
│   └── blog
│       ├── article
│       │   ├── category_archive.html
│       │   ├── date_archive.html
│       │   ├── index.html
│       │   └── single.html
│       ├── base.html
│       ├── emails
│       │   └── new_comment.html
│       ├── feeds
│       │   └── description.html
│       └── snippets
│           └── article_list.html
├── templatetags
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── blogs.py
│   └── blogs.pyc
├── urls.py
├── urls.pyc
└── views
    ├── __init__.py
    ├── __init__.pyc
    ├── article.py
    └── article.pyc

12 directories, 45 files

UPDATE

Your project is reader. so that reader folder is project level folder not app level. You really shouldnt have project level models or views. Create an app and move your models and views into it. see: https://stackoverflow.com/a/2610797/884453

Additionally b/c its reader/reader/models.py you probably have the project folder on the path and so reader.models doesn't exist, but reader.reader.models i bet does.

Community
  • 1
  • 1
Francis Yaconiello
  • 10,829
  • 2
  • 35
  • 54
  • Yes, i have `__init__.py`, which is the default one, i mean it is empty. Do i need to overwrite it ? – United May 16 '13 at 18:17
  • no as long as its there, you python code should be able to see `models.py`... do you see an `__init__.pyc` and `models.pyc` files? those 2 files would indicate that your python code is able to see/interpret the contents of the reader app. – Francis Yaconiello May 16 '13 at 18:27
  • These are no `.pyc` files now. I have edited my question in order to add the `tree` result. – United May 16 '13 at 18:51