ImportError failure

25 views
Skip to first unread message

Juan Carlos

unread,
Oct 21, 2014, 10:35:05 PM10/21/14
to django...@googlegroups.com
Hi everyone,

When I execute
python manage.py runserver

it appers:
ImportError: cannot import name 'example' from 'exsite'

The relative code in the settings.py file is:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'exsite.example',
)

What can I do?

My django version is 1.7, with Python 2.7.  I'm new in this interesting world of Django.  Thanks for your help, and time.

Regards,
Juan

Serdar Dalgic

unread,
Oct 22, 2014, 7:53:06 AM10/22/14
to django...@googlegroups.com
Hi Juan,

I believe you might have a problem while importing "example". Can you
check the line you're importing example and where did you put this
"exsite.example" module?

Your directory structure should be like this:

mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
exsite/
__init__.py
example.py
another_app/
__init__.py
another_module.py

So that you can import exsite.example in your another_module.py like:

from exsite.example import AnyClassYouWantToImport

I hope this helps.

p.s. mind the "__init__.py"s on the modules you want to import. There
must be one in your "exsite" dir.
p.s.2. Instead of an example.py file under exsite dir, you may have
written it under __init__.py file as

mysite/
...
mysite/
__init__.py
...

in this __init__.py, you may have
class Example(object):
...
...

this is OK either ;)


- Serdar Dalgıç <s...@serdardalgic.org>
FLOSS Developer, Life & Nature Hacker
twitter:
https://twitter.com/serdaroncode
https://twitter.com/serdarintowild
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/13bae8aa-77d9-4ba6-b038-d9ce37a37c9c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Juan Carlos

unread,
Oct 23, 2014, 12:34:06 AM10/23/14
to django...@googlegroups.com
Hi Serdar,
Sure, you're right.
Thanks, thank you very much!
Regards,
Juan
Reply all
Reply to author
Forward
0 new messages