pythondjangodjango-shell

Django Shell API KeyError


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"


Solution

  • 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