Django 1.7: ImportError: No module named <appname>.models

3,144 views
Skip to first unread message

Malik Rumi

unread,
Aug 11, 2014, 9:43:29 AM8/11/14
to django...@googlegroups.com

#admin.py:

    from apps.<appname>.models import Articles, Sections

ImportError: No module named <appname>.models

 

I have seen this error before, and it went away when I changed INSTALLED APPS from <appname> to apps.<appname> because I have all my apps in a folder called apps. Now I have changed even that to <appname>Config because of the 1.7 change to how this works. Apps.py is two levels down from here, so I don’t think there is a collision issue.

I tried changing the import statement to match the <appname>Config in INSTALLED APPS, but that just gave me the same error with the *Config name instead.

This is my model, it is clearly there, so I don’t know why or where this error is coming from or where to look to fix it. <appname> is all lower case, both in the Django directory and in admin.py. Just for the hell of it I capitalized <Appname> in admin.py, but I still get the same error. 

Malik Rumi

unread,
Aug 11, 2014, 1:35:50 PM8/11/14
to django...@googlegroups.com
UPDATE

What is “.models”, why and when do we import from it, and how is it different from importing from “models”?

I’ve never seen this .models before. I saw it the first time this morning in the documentation https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.register when trying to solve this problem. But it just a casual mention, not an explanation. As I understood it, this was only for those choosing to use the new register decorator, so I didn’t worry about it. Now I’ve seen it again, in a video by a guy using 1.6 who, at least so far, has made no reference to a decorator of any kind.

Is this the source of my problems? Where is the documentation on “.models”? Yes, I have looked and found zip.

Thanks.

Tyrel Souza

unread,
Aug 11, 2014, 1:40:48 PM8/11/14
to django...@googlegroups.com
It's checking for models.py in the current module and it's knowns as a "relative import"

Malik Rumi

unread,
Aug 11, 2014, 9:53:31 PM8/11/14
to django...@googlegroups.com
Ok, changing to .models seems to have fixed that error. On to the rest.... Thx!

ngangsia akumbo

unread,
Aug 12, 2014, 5:19:34 AM8/12/14
to django...@googlegroups.com
i have had this same erroe too but it happed that i include instead the module class name in the settings.py file

make sure u are having the name of the app in the settings.py file

Leonard Cohen

unread,
Apr 18, 2017, 4:18:01 PM4/18/17
to Django users
I WENT ALMOST CRAZY thanx a lot !!! ;)
Reply all
Reply to author
Forward
0 new messages