8

I am importing models in django shell API but i get the below error. Here is how it occurs:

python manage.py shell
from .models import Device

I get:

File "<console>", line 1, in <module> KeyError: "'__name__' not in globals"

1 Answers1

23

Try putting the app name before ".models". Here .models trying to import from models.py in the current directory but models.py is actually located in the app directory.

>> from [app_name].models import Device
Abu Sayem
  • 498
  • 5
  • 13