Wednesday, October 22, 2014

Re: ImportError failure

Hi Serdar,
Sure, you're right.
Thanks, thank you very much!
Regards,
Juan

El miércoles, 22 de octubre de 2014 06:53:06 UTC-5, Serdar Dalgic escribió:
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


On Wed, Oct 22, 2014 at 5:35 AM, Juan Carlos <juanca...@gmail.com> wrote:
> 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
>
> --
> 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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/59475bc6-8e4e-466d-9db9-1ecb7a4e4b9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment