ValueError: Attempted relative import in non-package

251 views
Skip to first unread message

darkbl...@gmail.com

unread,
Jul 8, 2018, 9:12:26 AM7/8/18
to Django users
hi all
help plz :)
as brief i am using django an linux
i create project and app in this project called movies
in models i create 2 classes mdb and mm
in views when i try to import class from model.py give me error

from .models import mdb
output:

Traceback (most recent call last):
File "/root/Desktop/website/movies/views.py", line 4, in <module>
from .models import mdb
ValueError: Attempted relative import in non-package

any ideas ? thanks in advance

Swati Pushp

unread,
Jul 8, 2018, 9:23:43 AM7/8/18
to django...@googlegroups.com
from .models import mdb
Please do import this class in views.py

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9c603e4c-5b68-4b0e-bfc4-7d23d410927e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mottaz hejaze

unread,
Jul 8, 2018, 10:10:22 AM7/8/18
to Django users
make sure that __init__.py file exists and not deleted

Melvyn Sopacua

unread,
Jul 8, 2018, 2:38:10 PM7/8/18
to django...@googlegroups.com
On zondag 8 juli 2018 08:40:03 CEST darkbl...@gmail.com wrote:

> Traceback (most recent call last):
> File "/root/Desktop/website/movies/views.py", line 4, in <module>
> from .models import mdb
> ValueError: Attempted relative import in non-package

You should really create your "movies app" with:

`python manage.py startapp movies`

That will create the correct boilerplate.

--
Melvyn Sopacua
Reply all
Reply to author
Forward
0 new messages